def test_auth_response_token_encoding(self):
        # without username, testing basics
        auth_response = AuthResponse(self.private_key_hex, RYAN_PROFILE)
        auth_response_token = auth_response.token()

        decoded_token = AuthResponse.decode(auth_response_token)
        payload = decoded_token['payload']
        self.assertEqual(payload['public_keys'][0], self.public_key_hex)
        self.assertEqual(get_address_from_did(payload['iss']),
                         self.public_key.address())
        self.assertEqual(payload['profile'], self.profile)
        self.assertEqual(payload['username'], None)

        self.assertTrue(AuthResponse.verify(auth_response_token))

        # with username
        with requests_mock.mock() as m:
            m.get(LOCALHOST_CORE_API + NAME_LOOKUP_URL + self.username,
                  text=json.dumps({'address': self.public_key.address()}))
            auth_response = AuthResponse(self.private_key_hex, RYAN_PROFILE,
                                         self.username)
            auth_response_token = auth_response.token()

            self.assertTrue(
                do_public_keys_match_username(
                    auth_response_token, Tokenizer(),
                    AuthResponse.decode(auth_response_token)))
            self.assertTrue(AuthResponse.verify(auth_response_token))
    def test_anon_auth_response_encoding(self):
        challenge = str(uuid.uuid4())
        auth_response = AuthResponse(
            self.private_key_hex, self.public_key_hex, self.challenge)
        auth_response_token = auth_response.token()

        is_valid_token = AuthResponse.verify(auth_response_token, self.resolver)
        self.assertTrue(is_valid_token)
Esempio n. 3
0
    def test_anon_auth_response_encoding(self):
        challenge = str(uuid.uuid4())
        auth_response = AuthResponse(self.private_key_hex, self.public_key_hex,
                                     self.challenge)
        auth_response_token = auth_response.token()

        is_valid_token = AuthResponse.verify(auth_response_token,
                                             self.resolver)
        self.assertTrue(is_valid_token)
    def test_auth_response_token_encoding(self):
        challenge = str(uuid.uuid4())
        auth_response = AuthResponse(
            self.private_key.to_pem(), self.private_key.public_key().to_hex(),
            self.challenge, self.blockchainid, self.master_public_key,
            self.chain_path)
        auth_response_token = auth_response.token()

        is_valid_token = AuthResponse.verify(auth_response_token, self.resolver)
        self.assertTrue(is_valid_token)
    def test_auth_response_token_encoding(self):
        challenge = str(uuid.uuid4())
        auth_response = AuthResponse(
            self.private_key_hex, self.public_key_hex,
            self.challenge, blockchain_id=self.blockchainid,
            public_keychain=self.public_keychain, chain_path=self.chain_path)
        auth_response_token = auth_response.token()

        is_valid_token = AuthResponse.verify(auth_response_token, self.resolver)
        self.assertTrue(is_valid_token)
Esempio n. 6
0
    def test_auth_response_token_encoding(self):
        challenge = str(uuid.uuid4())
        auth_response = AuthResponse(self.private_key_hex,
                                     self.public_key_hex,
                                     self.challenge,
                                     blockchain_id=self.blockchainid,
                                     public_keychain=self.public_keychain,
                                     chain_path=self.chain_path)
        auth_response_token = auth_response.token()

        is_valid_token = AuthResponse.verify(auth_response_token,
                                             self.resolver)
        self.assertTrue(is_valid_token)