Skip to content

Commit

Permalink
Merge commit '00f38b94b70fa5306de27733386a10e233f2a76c'
Browse files Browse the repository at this point in the history
# Conflicts:
#	server/test/api/test_collaboration.py
  • Loading branch information
baszoetekouw committed Nov 21, 2023
2 parents 8aea300 + 00f38b9 commit fca7905
Show file tree
Hide file tree
Showing 94 changed files with 942 additions and 781 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
max_line_length = 120
max_line_length = 128

[*.{yml,yaml,yml.j2,yaml.j2}]
max_line_length = 100
indent_size = 2
indent_size = 2
23 changes: 23 additions & 0 deletions misc/scale-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

if [ "$1" = "" ]
then
echo "Please specify input image"
fi
if [ "$2" = "" ]
then
echo "Please specify xxioutimage"
fi

IN=$1
OUT=$2

W=480
H=348

convert "$IN" -resize "${W}x${H}^" -background '#ffffff00' -gravity center -extent "${W}x${H}" "$OUT"

file "$OUT"

exit 0
2 changes: 1 addition & 1 deletion server/config/test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ retention:
cron_hour_of_day: 7

metadata:
idp_url: https://metadata.surfconext.nl/idps-metadata.xml
idp_url: "file://data/idps-metadata.xml"
parse_at_startup: False

service_bus:
Expand Down
10 changes: 8 additions & 2 deletions server/test/abstract_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import json
import os
import pathlib
import uuid
from base64 import b64encode
from time import time
Expand All @@ -23,7 +24,7 @@
from server.db.defaults import STATUS_EXPIRED, STATUS_SUSPENDED
from server.db.domain import Collaboration, User, Service, ServiceAup, UserToken, Invitation, \
PamSSOSession, Group, CollaborationMembership
from server.test.seed import seed, sarah_name
from server.test.seed import seed, user_sarah_name
from server.tools import read_file

# See api_users in config/test_config.yml
Expand Down Expand Up @@ -56,6 +57,11 @@ def setUpClass(cls):
config = app.app_config
config["profile"] = None
config.test = True

# point config to correct metadata file
metadata_filename = pathlib.Path(__file__).parent.resolve() / "data" / "idps-metadata.xml"
app.app_config.metadata.idp_url = f"file:///{metadata_filename}"

AbstractTest.app = app

@staticmethod
Expand Down Expand Up @@ -242,7 +248,7 @@ def get_authn_response(file):
xml_authn_signed = OneLogin_Saml2_Utils.add_sign(xml_response, key, cert)
return b64encode(xml_authn_signed)

def mark_user_ssid_required(self, name=sarah_name, home_organisation_uid=None, schac_home_organisation=None):
def mark_user_ssid_required(self, name=user_sarah_name, home_organisation_uid=None, schac_home_organisation=None):
user = self.find_entity_by_name(User, name)
user.ssid_required = True
if home_organisation_uid:
Expand Down
8 changes: 4 additions & 4 deletions server/test/api/test_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from server.auth.secrets import hash_secret_key
from server.db.domain import Organisation, ApiKey
from server.test.abstract_test import AbstractTest
from server.test.seed import uuc_name
from server.test.seed import unihard_name


class TestApiKey(AbstractTest):
Expand All @@ -12,12 +12,12 @@ def test_api_key_flow(self):
pre_count = ApiKey.query.count()
secret = self.get("/api/api_keys")["value"]

organisation = self.find_entity_by_name(Organisation, uuc_name)
organisation = self.find_entity_by_name(Organisation, unihard_name)

api_key = self.post("/api/api_keys",
body={"organisation_id": organisation.id, "hashed_secret": secret, "description": "Test"})
self.assertIsNotNone(api_key["id"])
organisation = self.find_entity_by_name(Organisation, uuc_name)
organisation = self.find_entity_by_name(Organisation, unihard_name)
self.assertEqual(organisation.id, api_key["organisation_id"])
self.assertNotEqual(secret, api_key["hashed_secret"])

Expand All @@ -42,7 +42,7 @@ def security_error():

def test_api_key_tampering(self):
secret = self.get("/api/api_keys")["value"]
organisation = self.find_entity_by_name(Organisation, uuc_name)
organisation = self.find_entity_by_name(Organisation, unihard_name)
self.post("/api/api_keys", body={"organisation_id": organisation.id, "hashed_secret": secret + "nope"},
response_status_code=403)

Expand Down
24 changes: 12 additions & 12 deletions server/test/api/test_audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from server.db.audit_mixin import ACTION_DELETE, ACTION_CREATE, ACTION_UPDATE, AuditLog
from server.db.domain import User, Collaboration, Service, Organisation, Group
from server.test.abstract_test import AbstractTest
from server.test.seed import service_cloud_name, ai_computing_name, \
service_mail_name, invitation_hash_curious, organisation_invitation_hash, uuc_name, group_science_name, sarah_name, \
james_name
from server.test.seed import service_cloud_name, co_ai_computing_name, \
service_mail_name, invitation_hash_curious, unihard_invitation_hash, unihard_name, group_science_name, user_sarah_name, \
user_james_name


class TestAuditLog(AbstractTest):
Expand All @@ -25,12 +25,12 @@ def test_me(self):

def test_me_impersonation(self):
self.login("urn:john")
user_id = self.find_entity_by_name(User, james_name).id
user_id = self.find_entity_by_name(User, user_james_name).id
res = self.get("/api/audit_logs/me", with_basic_auth=False, headers={"X-IMPERSONATE-ID": str(user_id)})
self.assertEqual(2, len(res))

def test_other_(self):
sarah = self.find_entity_by_name(User, sarah_name)
sarah = self.find_entity_by_name(User, user_sarah_name)
sarah_id = sarah.id
self.login("urn:sarah")
body = {
Expand All @@ -42,13 +42,13 @@ def test_other_(self):
self.assertEqual("sarah", res["users"][0]["username"])

def test_other_403(self):
sarah = self.find_entity_by_name(User, sarah_name)
sarah = self.find_entity_by_name(User, user_sarah_name)
self.login("urn:mary")
self.get(f"/api/audit_logs/other/{sarah.id}", response_status_code=403)

def test_services_info(self):
self.login("urn:john")
collaboration_id = self.find_entity_by_name(Collaboration, ai_computing_name).id
collaboration_id = self.find_entity_by_name(Collaboration, co_ai_computing_name).id
service_cloud_id = self.find_entity_by_name(Service, service_cloud_name).id

self.put("/api/collaborations_services/", body={
Expand All @@ -70,7 +70,7 @@ def test_collaboration(self):
self.put("/api/invitations/accept", body={"hash": invitation_hash_curious}, with_basic_auth=False)

self.login("urn:admin")
collaboration_id = self.find_entity_by_name(Collaboration, ai_computing_name).id
collaboration_id = self.find_entity_by_name(Collaboration, co_ai_computing_name).id

self.login()
res = self.get(f"/api/audit_logs/info/{collaboration_id}/collaborations")
Expand All @@ -84,10 +84,10 @@ def test_collaboration(self):

def test_organisation(self):
self.login("urn:sarah")
self.put("/api/organisation_invitations/accept", body={"hash": organisation_invitation_hash},
self.put("/api/organisation_invitations/accept", body={"hash": unihard_invitation_hash},
with_basic_auth=False)

organisation_id = self.find_entity_by_name(Organisation, uuc_name).id
organisation_id = self.find_entity_by_name(Organisation, unihard_name).id
self.login()
res = self.get(f"/api/audit_logs/info/{organisation_id}/organisations")

Expand All @@ -114,7 +114,7 @@ def test_groups(self):

def test_activity(self):
self.login("urn:sarah")
self.put("/api/organisation_invitations/accept", body={"hash": organisation_invitation_hash},
self.put("/api/organisation_invitations/accept", body={"hash": unihard_invitation_hash},
with_basic_auth=False)

self.login()
Expand All @@ -138,7 +138,7 @@ def test_activity(self):
self.assertEqual(2, len(res["users"]))

def test_no_last_activity_date_only_audit_logs(self):
collaboration = self.find_entity_by_name(Collaboration, ai_computing_name)
collaboration = self.find_entity_by_name(Collaboration, co_ai_computing_name)
collaboration.last_activity_date = datetime.now()
self.save_entity(collaboration)
audit_logs = AuditLog.query.all()
Expand Down
4 changes: 2 additions & 2 deletions server/test/api/test_aup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from server.db.db import db
from server.db.domain import User, Aup
from server.test.abstract_test import AbstractTest
from server.test.seed import sarah_name
from server.test.seed import user_sarah_name


class TestAup(AbstractTest):
Expand All @@ -13,7 +13,7 @@ def test_links(self):
self.assertEqual("1", links["version"])

def test_agree(self):
sarah = self.find_entity_by_name(User, sarah_name)
sarah = self.find_entity_by_name(User, user_sarah_name)
db.session.delete(Aup.query.filter(Aup.user == sarah).first())

self.login("urn:sarah")
Expand Down
Loading

0 comments on commit fca7905

Please sign in to comment.