Пример #1
0
    def identity(self):
        """ Returns the identity for the auth context. """
        if self.oauthtoken:
            scope_set = scopes_from_scope_string(self.oauthtoken.scope)
            return QuayDeferredPermissionUser.for_user(self.oauthtoken.authorized_user, scope_set)

        if self.authed_user:
            return QuayDeferredPermissionUser.for_user(self.authed_user)

        if self.token:
            return Identity(self.token.get_code(), "token")

        if self.signed_data:
            identity = Identity(None, "signed_grant")
            identity.provides.update(self.signed_data["grants"])
            return identity

        return None
Пример #2
0
def test_superuser_matrix(superuser, normie):
    test_cases = [
        (superuser, {scopes.SUPERUSER}, True),
        (superuser, {scopes.DIRECT_LOGIN}, True),
        (superuser, {scopes.READ_USER, scopes.SUPERUSER}, True),
        (superuser, {scopes.READ_USER}, False),
        (normie, {scopes.SUPERUSER}, False),
        (normie, {scopes.DIRECT_LOGIN}, False),
        (normie, {scopes.READ_USER, scopes.SUPERUSER}, False),
        (normie, {scopes.READ_USER}, False),
    ]

    for user_obj, scope_set, expected in test_cases:
        perm_user = QuayDeferredPermissionUser.for_user(user_obj, scope_set)
        has_su = perm_user.can(SuperUserPermission())
        assert has_su == expected