def test_get_magic_castle_by_hostname(database_connection): user = AnonymousUser(database_connection) magic_castle = user.get_magic_castle_by_hostname( "valid1.calculquebec.cloud") assert magic_castle.get_hostname() == "valid1.calculquebec.cloud" assert magic_castle.get_owner() == "*****@*****.**" assert magic_castle.get_status() == ClusterStatusCode.PROVISIONING_SUCCESS
def test_create_empty_magic_castle(database_connection): user = AnonymousUser(database_connection) magic_castle = user.create_empty_magic_castle() magic_castle.set_configuration({ "cluster_name": "anon123", "domain": "sub.example.com", "image": "CentOS-7-x64-2019-07", "nb_users": 10, "instances": { "mgmt": { "type": "p4-6gb", "count": 1 }, "login": { "type": "p4-6gb", "count": 1 }, "node": { "type": "p2-3gb", "count": 1 }, }, "storage": { "type": "nfs", "home_size": 100, "project_size": 50, "scratch_size": 50, }, "public_keys": [], "guest_passwd": "", "os_floating_ips": [], }) magic_castle.plan_creation() result = database_connection.execute( "SELECT hostname, cluster_name, domain, status, plan_type, owner FROM magic_castles WHERE hostname=?", ("anon123.sub.example.com", ), ).fetchall() assert result == [( "anon123.sub.example.com", "anon123", "sub.example.com", "created", "build", None, )]
def decorator(*args, **kwargs): auth_type = AuthType(config.get("auth_type") or "NONE") with DatabaseManager.connect() as database_connection: if auth_type == AuthType.SAML: try: # Note: Request headers are interpreted as ISO Latin 1 encoded strings. # Therefore, special characters and accents in givenName and surname are not correctly decoded. user = AuthenticatedUser( database_connection, edu_person_principal_name=request. headers["eduPersonPrincipalName"], given_name=request.headers["givenName"], surname=request.headers["surname"], mail=request.headers["mail"], ) except KeyError: # Missing an authentication header raise UnauthenticatedException else: user = AnonymousUser(database_connection) return route_handler(user, *args, **kwargs)
def test_get_all_magic_castles(database_connection): all_magic_castles = AnonymousUser(database_connection).get_all_magic_castles() assert [magic_castle.get_hostname() for magic_castle in all_magic_castles] == [ "buildplanning.calculquebec.cloud", "created.calculquebec.cloud", "empty-state.calculquebec.cloud", "empty.calculquebec.cloud", "missingfloatingips.c3.ca", "missingnodes.sub.example.com", "noowner.calculquebec.cloud", "valid1.calculquebec.cloud", ] assert [magic_castle.get_status() for magic_castle in all_magic_castles] == [ ClusterStatusCode.PLAN_RUNNING, ClusterStatusCode.CREATED, ClusterStatusCode.BUILD_ERROR, ClusterStatusCode.BUILD_ERROR, ClusterStatusCode.BUILD_RUNNING, ClusterStatusCode.BUILD_ERROR, ClusterStatusCode.PROVISIONING_SUCCESS, ClusterStatusCode.PROVISIONING_SUCCESS, ]
def test_full_name(database_connection): assert AnonymousUser(database_connection).full_name == None