Exemple #1
0
    def create_client(self):
        dataset = DictDBWrap(USERDB)
        dataset.register_scope('https://dirg.org.umu.se/uma/read', 'get')

        resource_owner = 'linda'

        self.srv = ResourceServer(dataset, resource_owner)
        # map client API operation (HTTP GET) to scope
        self.srv.rs_handler.op2scope = {
            'GET': 'https://dirg.org.umu.se/uma/read'}
Exemple #2
0
    def create_client(self):
        dataset = DictDBWrap(USERDB)
        dataset.register_scope('https://dirg.org.umu.se/uma/read', 'get')

        resource_owner = 'linda'

        self.srv = ResourceServer(dataset, resource_owner)
        # map client API operation (HTTP GET) to scope
        self.srv.rs_handler.op2scope = {
            'GET': 'https://dirg.org.umu.se/uma/read'
        }
Exemple #3
0
    def create_client(self):
        dataset = DictDBWrap(USERDB)
        # The scope to dataset operation map
        dataset.register_scope('https://dirg.org.umu.se/uma/read', 'get')

        client = Client({}, client_authn_methods=CLIENT_AUTHN_METHOD)

        resource_owner = 'hans'
        self.rsh = ResourceSetHandler(dataset, client, resource_owner)

        self.rsh.client.provider_info = {
            "resource_set_registration_endpoint": 'https://as.example.com/rsr'}

        # No the real PAT obviously
        self.rsh.token["PAT"] = 'pat'

        # map client API operation (HTTP GET) to scope
        self.rsh.op2scope = {'GET': 'https://dirg.org.umu.se/uma/read'}
Exemple #4
0
    def create_client(self):
        dataset = DictDBWrap(USERDB)
        # The scope to dataset operation map
        dataset.register_scope('https://dirg.org.umu.se/uma/read', 'get')

        client = Client({}, client_authn_methods=CLIENT_AUTHN_METHOD)

        resource_owner = 'hans'
        self.rsh = ResourceSetHandler(dataset, client, resource_owner)

        self.rsh.client.provider_info = {
            "resource_set_registration_endpoint": 'https://as.example.com/rsr'
        }

        # No the real PAT obviously
        self.rsh.token["PAT"] = 'pat'

        # map client API operation (HTTP GET) to scope
        self.rsh.op2scope = {'GET': 'https://dirg.org.umu.se/uma/read'}
Exemple #5
0
 def __init__(self, db, **kwargs):
     DictDBWrap.__init__(self, db, **kwargs)
     self.base_url = kwargs["baseurl"]
     self.scopes = list(OP2SCOPE.values())
Exemple #6
0
 def create_db(self):
     self.dw = DictDBWrap(USERDB.copy())
     self.dw.scopes2op["https://dirg.org.umu.se/uma/read"] = self.dw.get
Exemple #7
0
class TestDictDBWrap(object):
    @pytest.fixture(autouse=True)
    def create_db(self):
        self.dw = DictDBWrap(USERDB.copy())
        self.dw.scopes2op["https://dirg.org.umu.se/uma/read"] = self.dw.get

    def test_build_resource_set_descriptions(self):
        rsd = self.dw.build_resource_set_descriptions("hans")
        assert len(rsd) == 5
        # Pick one resource set description and check it
        rs = rsd["hans:sn:Granberg"]
        assert isinstance(rs, ResourceSetDescription)
        assert rs["scopes"] == ['https://dirg.org.umu.se/uma/read']
        assert rs['name'] == 'hans sn=Granberg'

    def test_update_resource_set_description_no_change(self):
        _ = self.dw.build_resource_set_descriptions("hans")
        diff = self.dw.update_resource_set_description('hans')
        assert diff == {"delete": [], "add": {}, "update": {}}

    def test_update_resource_set_description_ava_add(self):
        _ = self.dw.build_resource_set_descriptions("hans")
        self.dw.update('hans', {"middleName": "pippi"})
        diff = self.dw.update_resource_set_description('hans')
        assert diff["delete"] == []
        assert diff["update"] == {}

        assert len(diff["add"]) == 1
        assert list(diff['add'].keys())[0] == "hans:middleName:pippi"

    def test_update_resource_set_description_item_del(self):
        _ = self.dw.build_resource_set_descriptions("hans")
        self.dw.delete('hans')
        diff = self.dw.update_resource_set_description('hans')
        assert _eq(diff["delete"],
                   ['hans:eduPersonNickname:Hasse',
                    'hans:displayName:Hans Granberg',
                    'hans:middleName:pippi', 'hans:givenName:Hans',
                    'hans:sn:Granberg',
                    'hans:email:[email protected]'])
        assert diff["update"] == {}
        assert diff["add"] == {}

    def test_get(self):
        self.dw.update('hans', USERDB["hans"])
        ava = self.dw.get('hans')
        assert _eq(list(ava.keys()),
                   ['sn', 'displayName', 'eduPersonNickname', 'email',
                    'middleName', 'givenName'])
        va = self.dw.get('hans', 'sn')
        assert va == 'Granberg'
Exemple #8
0
 def create_db(self):
     self.dw = DictDBWrap(USERDB.copy())
     self.dw.scopes2op["https://dirg.org.umu.se/uma/read"] = self.dw.get
Exemple #9
0
class TestDictDBWrap(object):
    @pytest.fixture(autouse=True)
    def create_db(self):
        self.dw = DictDBWrap(USERDB.copy())
        self.dw.scopes2op["https://dirg.org.umu.se/uma/read"] = self.dw.get

    def test_build_resource_set_descriptions(self):
        rsd = self.dw.build_resource_set_descriptions("hans")
        assert len(rsd) == 5
        # Pick one resource set description and check it
        rs = rsd["hans:sn:Granberg"]
        assert isinstance(rs, ResourceSetDescription)
        assert rs["scopes"] == ['https://dirg.org.umu.se/uma/read']
        assert rs['name'] == 'hans sn=Granberg'

    def test_update_resource_set_description_no_change(self):
        _ = self.dw.build_resource_set_descriptions("hans")
        diff = self.dw.update_resource_set_description('hans')
        assert diff == {"delete": [], "add": {}, "update": {}}

    def test_update_resource_set_description_ava_add(self):
        _ = self.dw.build_resource_set_descriptions("hans")
        self.dw.update('hans', {"middleName": "pippi"})
        diff = self.dw.update_resource_set_description('hans')
        assert diff["delete"] == []
        assert diff["update"] == {}

        assert len(diff["add"]) == 1
        assert list(diff['add'].keys())[0] == "hans:middleName:pippi"

    def test_update_resource_set_description_item_del(self):
        _ = self.dw.build_resource_set_descriptions("hans")
        self.dw.delete('hans')
        diff = self.dw.update_resource_set_description('hans')
        assert _eq(diff["delete"], [
            'hans:eduPersonNickname:Hasse', 'hans:displayName:Hans Granberg',
            'hans:middleName:pippi', 'hans:givenName:Hans', 'hans:sn:Granberg',
            'hans:email:[email protected]'
        ])
        assert diff["update"] == {}
        assert diff["add"] == {}

    def test_get(self):
        self.dw.update('hans', USERDB["hans"])
        ava = self.dw.get('hans')
        assert _eq(list(ava.keys()), [
            'sn', 'displayName', 'eduPersonNickname', 'email', 'middleName',
            'givenName'
        ])
        va = self.dw.get('hans', 'sn')
        assert va == 'Granberg'