Commit 809dec6d authored by Loïc Dachary's avatar Loïc Dachary
Browse files

Merge branch 'wip-authenticate' into 'master'

interfaces: add authenticate forge method

See merge request fedeproxy/fedeproxy!10
parents 99aecdab d97de71d
Pipeline #23778 canceled with stage
......@@ -14,6 +14,10 @@ class Gitea(Forge):
self.url = url
self._session()
def authenticate(self, **kwargs):
self._session()
self.login(kwargs["username"], kwargs["password"])
def _session(self):
self.s = requests.Session()
self.s.api = f"{self.url}/api/v1"
......
......@@ -20,6 +20,10 @@ class GitLab(Forge):
self.url = url
self._session()
def authenticate(self, **kwargs):
self._session()
self.login(kwargs["username"], kwargs["password"])
def _session(self):
self.s = requests.Session()
if "REQUESTS_CA_BUNDLE" not in os.environ:
......
def verify_project_create(forge):
forge.authenticate(username="root", password="Wrobyak4")
user = "testuser1"
email = "testuser1@example.com"
forge.user_create(user, email)
forge.project_delete(user, user, "testproject")
assert forge.project_get(user, user, "testproject") is None
p = forge.project_create("root", user, user, "testproject")
assert p["id"] == forge.project_create("root", user, user, "testproject")["id"]
assert forge.project_delete(user, user, "testproject") is True
assert forge.project_delete(user, user, "testproject") is False
assert forge.user_delete(user) is True
def verify_user_create(forge):
forge.authenticate(username="root", password="Wrobyak4")
user = "testuser1"
email = "testuser1@example.com"
forge.user_delete(user)
u = forge.user_create(user, email)
assert u["id"] == forge.user_create(user, email)["id"]
assert forge.user_delete(user) is True
assert forge.user_get(user) is None
assert forge.user_delete(user) is False
......@@ -2,6 +2,7 @@ import os
import pytest
from . import test_forge
from .gitea import Gitea
......@@ -9,31 +10,14 @@ from .gitea import Gitea
def gitea():
ip = os.environ.get("MY_IP", "0.0.0.0")
gitea = Gitea(f"http://{ip}:8781")
gitea.login("gitea_admin", "admin123")
return gitea
@pytest.mark.gitea
def test_project_create(gitea):
user = "testuser1"
email = "testuser1@example.com"
gitea.user_create(user, email)
gitea.project_delete(user, user, "testproject")
assert gitea.project_get(user, user, "testproject") is None
p = gitea.project_create("root", user, user, "testproject")
assert p["id"] == gitea.project_create("root", user, user, "testproject")["id"]
assert gitea.project_delete(user, user, "testproject") is True
assert gitea.project_delete(user, user, "testproject") is False
assert gitea.user_delete(user) is True
test_forge.verify_project_create(gitea)
@pytest.mark.gitea
def test_user_create(gitea):
user = "testuser1"
email = "testuser1@example.com"
gitea.user_delete(user)
u = gitea.user_create(user, email)
assert u["id"] == gitea.user_create(user, email)["id"]
assert gitea.user_delete(user) is True
assert gitea.user_get(user) is None
assert gitea.user_delete(user) is False
test_forge.verify_user_create(gitea)
......@@ -3,6 +3,7 @@ import os
import pytest
from . import test_forge
from .gitlab import GitLab
......@@ -10,37 +11,22 @@ from .gitlab import GitLab
def gitlab():
ip = os.environ.get("MY_IP", "0.0.0.0")
gitlab = GitLab(f"http://{ip}:8181")
gitlab.login("root", "Wrobyak4")
return gitlab
@pytest.mark.gitlab
def test_project_create(gitlab):
user = "testuser1"
email = "testuser1@example.com"
gitlab.user_create(user, email)
gitlab.project_delete(user, user, "testproject")
assert gitlab.project_get(user, user, "testproject") is None
p = gitlab.project_create("root", user, user, "testproject")
assert p["id"] == gitlab.project_create("root", user, user, "testproject")["id"]
assert gitlab.project_delete(user, user, "testproject") is True
assert gitlab.project_delete(user, user, "testproject") is False
assert gitlab.user_delete(user) is True
test_forge.verify_project_create(gitlab)
@pytest.mark.gitlab
def test_user_create(gitlab):
user = "testuser1"
email = "testuser1@example.com"
gitlab.user_delete(user)
u = gitlab.user_create(user, email)
assert u["id"] == gitlab.user_create(user, email)["id"]
assert gitlab.user_delete(user) is True
assert gitlab.user_delete(user) is False
test_forge.verify_user_create(gitlab)
@pytest.mark.gitlab
def test_issue_create(gitlab):
gitlab.authenticate(username="root", password="Wrobyak4")
gitlab.project_delete("root", "root", "testproject")
p = gitlab.project_create("root", "root", "root", "testproject")
title = "THE TITLE"
......@@ -54,6 +40,7 @@ def test_issue_create(gitlab):
@pytest.mark.gitlab
def test_project_export(gitlab, tmpdir):
gitlab.authenticate(username="root", password="Wrobyak4")
gitlab.project_delete("root", "root", "testproject")
gitlab.project_create("root", "root", "root", "testproject")
exported = f"{tmpdir}/testproject.tar.gz"
......
......@@ -2,6 +2,10 @@ import abc
class Forge(abc.ABC):
@abc.abstractmethod
def authenticate(self, **kwargs):
...
@abc.abstractmethod
def user_get(self, user):
...
......@@ -11,13 +15,17 @@ class Forge(abc.ABC):
...
@abc.abstractmethod
def project_get(self, user, namespace, project):
def user_delete(self, user):
...
@abc.abstractmethod
def project_delete(self, user, namespace, project):
def project_get(self, user, namespace, project):
...
@abc.abstractmethod
def project_create(self, admin, user, namespace, project, **data):
...
@abc.abstractmethod
def project_delete(self, user, namespace, project):
...
......@@ -13,7 +13,7 @@ function setup_gitea() {
success=false
for delay in 15 15 15 15 15 30 30 30 30 30 30 ; do
if curl --fail --verbose --data-binary "db_type=SQLite3&db_host=localhost%3A3306&db_user=root&db_passwd=&db_name=gitea&ssl_mode=disable&db_schema=&charset=utf8&db_path=%2Fdata%2Fgitea%2Fgitea.db&app_name=Gitea%3A+Git+with+a+cup+of+tea&repo_root_path=%2Fdata%2Fgit%2Frepositories&lfs_root_path=%2Fdata%2Fgit%2Flfs&run_user=git&domain=${MY_IP}&ssh_port=22&http_port=3000&app_url=http%3A%2F%2F${MY_IP}%3A878${serial}%2F&log_root_path=%2Fdata%2Fgitea%2Flog&smtp_host=&smtp_from=&smtp_user=&smtp_passwd=&enable_federated_avatar=on&no_reply_address=&password_algorithm=pbkdf2&admin_name=gitea_admin&admin_passwd=admin123&admin_confirm_passwd=admin123&admin_email=admin@example.com" http://${MY_IP}:878$serial/ ; then
if curl --fail --verbose --data-binary "db_type=SQLite3&db_host=localhost%3A3306&db_user=root&db_passwd=&db_name=gitea&ssl_mode=disable&db_schema=&charset=utf8&db_path=%2Fdata%2Fgitea%2Fgitea.db&app_name=Gitea%3A+Git+with+a+cup+of+tea&repo_root_path=%2Fdata%2Fgit%2Frepositories&lfs_root_path=%2Fdata%2Fgit%2Flfs&run_user=git&domain=${MY_IP}&ssh_port=22&http_port=3000&app_url=http%3A%2F%2F${MY_IP}%3A878${serial}%2F&log_root_path=%2Fdata%2Fgitea%2Flog&smtp_host=&smtp_from=&smtp_user=&smtp_passwd=&enable_federated_avatar=on&no_reply_address=&password_algorithm=pbkdf2&admin_name=root&admin_passwd=Wrobyak4&admin_confirm_passwd=Wrobyak4&admin_email=admin@example.com" http://${MY_IP}:878$serial/ ; then
success=true
break
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment