Example #1
0
 def setUp(self):
     mock_keypair = keychain.Keypair.from_secret_pem(
         key_bytes=TestSession.id_key_bytes)
     self.credentials = keychain.Credentials('me', mock_keypair)
     self.model = {
         'test_method': {
             'endpoint': 'https://myservice/my/endpoint',
             'method': 'GET',
             'arguments': {
                 'in_jwt': {
                     'location': 'jwt',
                     'required': True,
                 },
                 'in_url': {
                     'location': 'url',
                     'required': True,
                 },
                 'optional': {
                     'location': 'jwt',
                     'required': False,
                 },
                 'optional_in_url': {
                     'location': 'url',
                     'required': False,
                 },
             },
         }
     }
     self.session = session.ServerSession(self.credentials)
     self.service_creator = service.ServiceCreator()
     self.service = self.service_creator.create_service_class(
         'svc', self.model, self.session)
Example #2
0
    def setUp(self):
        mock_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.id_key_bytes)
        self.credentials = keychain.Credentials('me', mock_keypair)
        mock_project_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.proj_key_bytes)

        self.project_credentials = keychain.Credentials(
            'proj', mock_project_keypair)
        self.custom_config = dict()
        global_config = self.custom_config['GLOBAL'] = dict()
        global_config['base_url'] = 'https://myservice'

        test_service = self.custom_config['test_service'] = dict()
        test_method = test_service['test_method'] = dict()
        test_method['endpoint'] = '/my/endpoint'
        test_method['method'] = 'POST'
        test_arguments = test_method['arguments'] = dict()
        test_arguments['my_argument'] = {'location': 'jwt', 'required': True}
Example #3
0
    def test_service_class_with_project_creds(self):
        mock_proj_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.proj_key_bytes)
        proj_credentials = keychain.Credentials('proj-id', mock_proj_keypair)
        sess = session.ServerSession(self.credentials,
                                     project_credentials=proj_credentials)
        svc = self.service_creator.create_service_class(
            'svc', self.model, sess)

        self.assertEqual(svc.__class__.__name__, "svc")
        self.assertTrue(hasattr(svc, "test_method"))
Example #4
0
    def test_peer_credentials(self):
        base = session.SessionBase()
        self.assertIsNone(base.peer_credentials)

        cred = keychain.Credentials('me', keychain.BaseKeypair())

        base = session.SessionBase(peer_credentials=cred)
        self.assertIsInstance(base.peer_credentials, list)

        base = session.SessionBase(peer_credentials=[cred])
        self.assertIsInstance(base.peer_credentials, list)
Example #5
0
    def setUp(self):
        nonces.set_nonce_handlers(lambda _n: True, lambda _n: True)
        self.mock_id_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.id_key_bytes)
        self.mock_id_keypair.identity = 'device-id'

        self.id_credentials = keychain.Credentials(
            self.mock_id_keypair.identity, self.mock_id_keypair)

        self.mock_proj_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.proj_key_bytes)
        self.mock_proj_keypair.identity = 'proj-id'

        self.proj_credentials = keychain.Credentials(
            self.mock_proj_keypair.identity, self.mock_proj_keypair)

        self.mock_oneid_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.oneid_key_bytes)
        self.mock_oneid_keypair.identity = 'oneid-id'

        self.oneid_credentials = keychain.Credentials(
            self.mock_oneid_keypair.identity, self.mock_oneid_keypair)

        mock_peer_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.alt_key_bytes)
        mock_peer_keypair.identity = 'peer'

        self.peer_credentials = keychain.Credentials(
            mock_peer_keypair.identity, mock_peer_keypair)

        self.mock_resetA_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_A_bytes)
        self.mock_resetA_keypair.identity = 'resetA-id'

        self.resetA_credentials = keychain.Credentials(
            self.mock_resetA_keypair.identity, self.mock_resetA_keypair)

        self.mock_resetB_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_B_bytes)
        self.mock_resetB_keypair.identity = 'resetB-id'

        self.resetB_credentials = keychain.Credentials(
            self.mock_resetB_keypair.identity, self.mock_resetB_keypair)

        self.mock_resetC_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_C_bytes)
        self.mock_resetC_keypair.identity = 'resetC-id'

        self.resetC_credentials = keychain.Credentials(
            self.mock_resetC_keypair.identity, self.mock_resetC_keypair)
Example #6
0
    def setUp(self):
        mock_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.id_key_bytes)
        mock_keypair.identity = 'server'
        self.server_credentials = keychain.Credentials(mock_keypair.identity,
                                                       mock_keypair)

        mock_oneid_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.oneid_key_bytes)
        mock_oneid_keypair.identity = 'oneID'
        self.oneid_credentials = keychain.Credentials(
            mock_oneid_keypair.identity, mock_oneid_keypair)

        mock_project_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.proj_key_bytes)
        mock_project_keypair.identity = 'proj'
        self.project_credentials = keychain.Credentials(
            mock_project_keypair.identity, mock_project_keypair)
        mock_resetA_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_A_bytes)
        mock_resetA_keypair.identity = 'resetA-id'
        self.resetA_credentials = keychain.Credentials(
            mock_resetA_keypair.identity, mock_resetA_keypair)

        mock_resetB_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_B_bytes)
        mock_resetB_keypair.identity = 'resetB-id'
        self.resetB_credentials = keychain.Credentials(
            mock_resetB_keypair.identity, mock_resetB_keypair)

        mock_resetC_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_C_bytes)
        mock_resetC_keypair.identity = 'resetC-id'
        self.resetC_credentials = keychain.Credentials(
            mock_resetC_keypair.identity, mock_resetC_keypair)

        self.oneid_response = jwts.make_jwt({'a': 1}, mock_oneid_keypair)
        # TODO: JWS with both

        self.fake_config = {
            'GLOBAL': {
                'base_url': 'https://myservice',
            },
            'test_service': {
                'test_method': {
                    'endpoint': '/my/endpoint',
                    'method': 'GET',
                    'arguments': {},
                },
            },
        }
Example #7
0
    def setUp(self):
        self.mock_id_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.id_key_bytes)
        self.mock_id_keypair.identity = 'device-id'

        self.id_credentials = keychain.Credentials(
            self.mock_id_keypair.identity, self.mock_id_keypair)

        self.mock_proj_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.proj_key_bytes)
        self.mock_proj_keypair.identity = 'proj-id'

        self.proj_credentials = keychain.Credentials(
            self.mock_proj_keypair.identity, self.mock_proj_keypair)

        self.mock_oneid_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.oneid_key_bytes)
        self.mock_oneid_keypair.identity = 'oneid-id'

        self.oneid_credentials = keychain.Credentials(
            self.mock_oneid_keypair.identity, self.mock_oneid_keypair)

        self.mock_resetA_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_A_bytes)
        self.mock_resetA_keypair.identity = 'resetA-id'

        self.resetA_credentials = keychain.Credentials(
            self.mock_resetA_keypair.identity, self.mock_resetA_keypair)

        self.mock_resetB_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_B_bytes)
        self.mock_resetB_keypair.identity = 'resetB-id'

        self.resetB_credentials = keychain.Credentials(
            self.mock_resetB_keypair.identity, self.mock_resetB_keypair)

        self.mock_resetC_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_C_bytes)
        self.mock_resetC_keypair.identity = 'resetC-id'

        self.resetC_credentials = keychain.Credentials(
            self.mock_resetC_keypair.identity, self.mock_resetC_keypair)
 def test_invalid_keypair(self):
     with self.assertRaises(ValueError):
         keychain.Credentials(self.uuid, None)
 def test_basic_object(self):
     creds = keychain.Credentials(self.uuid, self.keypair)
     self.assertEqual(creds.id, self.uuid)
     self.assertEqual(creds.keypair, self.keypair)
Example #10
0
    def setUp(self):
        nonces.set_nonce_handlers(lambda _n: True, lambda _n: True)
        mock_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.id_key_bytes)
        mock_keypair.identity = 'id'
        self.id_credentials = keychain.Credentials(mock_keypair.identity,
                                                   mock_keypair)

        mock_oneid_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.oneid_key_bytes)
        mock_oneid_keypair.identity = 'oneID'
        self.oneid_credentials = keychain.Credentials(
            mock_oneid_keypair.identity, mock_oneid_keypair)

        mock_alt_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.alt_key_bytes)
        mock_alt_keypair.identity = 'alt'
        self.alt_credentials = keychain.Credentials(mock_alt_keypair.identity,
                                                    mock_alt_keypair)

        mock_project_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.proj_key_bytes)
        mock_project_keypair.identity = 'proj'
        self.project_credentials = keychain.Credentials(
            mock_project_keypair.identity, mock_project_keypair)
        mock_resetA_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_A_bytes)
        mock_resetA_keypair.identity = 'resetA-id'
        self.resetA_credentials = keychain.Credentials(
            mock_resetA_keypair.identity, mock_resetA_keypair)

        mock_resetB_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_B_bytes)
        mock_resetB_keypair.identity = 'resetB-id'
        self.resetB_credentials = keychain.Credentials(
            mock_resetB_keypair.identity, mock_resetB_keypair)

        mock_resetC_keypair = keychain.Keypair.from_secret_pem(
            key_bytes=TestSession.reset_key_C_bytes)
        mock_resetC_keypair.identity = 'resetC-id'
        self.resetC_credentials = keychain.Credentials(
            mock_resetC_keypair.identity, mock_resetC_keypair)

        # TODO: JWS with both

        self.fake_config = {
            'GLOBAL': {
                'base_url': 'https://myservice',
            },
            'test_service': {
                'test_method': {
                    'endpoint': '/my/endpoint',
                    'method': 'GET',
                    'arguments': {},
                },
            },
            'authenticate': {},
        }
        self.fake_config['authenticate']['project'] = {
            'endpoint': '/auth/generic_endpoint',
            'method': 'POST',
            'arguments': {
                'message': {
                    'location': 'jwt',
                    'required': True,
                },
            },
        }
        self.fake_config['authenticate']['edge_device'] = \
            self.fake_config['authenticate']['server'] = {

            'endpoint': '/auth/endpoint',
            'method': 'POST',
            'arguments': {
                'identity': {
                    'location': 'url',
                    'required': True,
                },
                'message': {
                    'location': 'jwt',
                    'required': True,
                },
            },
        }