Esempio n. 1
0
    def test_products_non_valid_token(self):
        """
        Test case for using non valid authentication token for products query

        """
        t = datetime.datetime.now()
        headers = lippuclient.generate_headers(
            account_id=self.testdata['valid_client1'],
            token=str(uuid.uuid4()),
            language="fi")
        response = lippuclient.product_query(self.envdata['base_url'], headers,
                                             t)
        logging.info("test_products_non_valid_token %s" % response.text)
        self.assertEqual(response.status_code, 403)
Esempio n. 2
0
    def test_init_auth_null_client(self):
        """
        Test case for init_auth

        Initiates authentication process with null as account.
        """
        # Initialize authentication
        headers = lippuclient.generate_headers(
            account_id=self.testdata['valid_client1'])
        r_init = lippuclient.authentication_init_request(
            self.envdata['base_url'], headers=headers, account_id=None)

        logging.info("test_init_auth_non_valid_client1, init response: %s" %
                     r_init.text)
        self.assertEqual(r_init.status_code, 400)
        self.assertEqual(r_init.json()['statusCode'], 400)
    def test_availability_non_valid_token(self):
        """
        Test case for using non valid authentication token for availability query

        """
        travel = self.testdata['travel_data']
        travel["travel"]["departureTimeEarliest"]  = zulu.now().shift(days=2).\
            replace(hour=14, minute=00).isoformat()
        headers = lippuclient.generate_headers(
            account_id=self.testdata['valid_client1'],
            token=str(uuid.uuid4()),
            language="fi")
        r = lippuclient.availability_request(self.envdata['base_url'],
                                             headers=headers,
                                             payload=travel)
        logging.info("test_availability_non_valid_token, response: %s" %
                     (r.json()))
        self.assertEqual(r.status_code, 403)
Esempio n. 4
0
    def test_commit_auth_invalid_signature(self):
        """
        Test case for commit_auth

        Creates a valid authentication token
        """

        headers = lippuclient.generate_headers(
            account_id=self.testdata['valid_client1'])
        r_init = lippuclient.authentication_init_request(
            self.envdata['base_url'],
            headers=headers,
            account_id=self.testdata['valid_client1'])

        logging.info("test_commit_auth_invalid_signature, init response: %s" %
                     r_init.text)
        self.assertEqual(r_init.status_code, 200)
        self.assertNotEqual(r_init.json()['nonce'], None)

        # Commit authentication and receive authentication token.
        nonce = str(uuid.uuid4())
        headers['X-Message-Id'] = str(uuid.uuid4())
        nonces = r_init.json()['nonce'] + nonce
        commit_body = {
            'data': str(uuid.uuid4()),
            'pubKeyId': self.testdata['key_id_client1'],
            'cnonce': nonce,
            'snonce': r_init.json()['nonce'],
            'alg': 'RSA+SHA256'
        }
        r_commit = requests.post(self.envdata['base_url'] +
                                 lippuclient.AUTHENTICATION_COMMIT_ENDPOINT,
                                 headers=headers,
                                 json=commit_body)

        logging.info(
            "test_commit_auth_invalid_signature, commit response: %s" %
            r_commit.text)
        self.assertEqual(r_commit.status_code, 403)
        pass
Esempio n. 5
0
    def test_commit_auth(self):
        """
        Test case for successful init_auth and commit_auth

        """
        t = zulu.now()
        account_id = self.testdata['valid_client1']

        headers = lippuclient.generate_headers(account_id=account_id)

        r_init = lippuclient.authentication_init_request(
            self.envdata['base_url'], headers, account_id)
        #r_init = requests.post(self.envdata['auth_url'] + '/init',
        #                         headers=headers, json={'account': account_id})
        logging.info("test_commit_auth, response for init: %s" % r_init.text)
        self.assertEqual(r_init.status_code, 200)
        self.assertNotEqual(r_init.json()['nonce'], None)
        self.assertEqual(r_init.json()['user'], account_id)
        self.assertNotEqual(r_init.json()['expires'], None)
        self.assertEqual(zulu.parse(r_init.json()['expires']) > t, True)

        # Commit authentication and receive authentication token.
        headers['X-Message-Id'] = str(uuid.uuid4())
        r_commit = lippuclient.authentication_commit_request(
            self.envdata['base_url'], headers,
            r_init.json()['nonce'], self.testdata['key_id_client1'],
            self.testdata['key_path_client1'], lippuclient.ALG_RSA_SHA256)
        logging.info("test_commit_auth, response for commit: %s" %
                     r_commit.text)

        self.assertEqual(r_commit.status_code, 200)
        self.assertNotEqual(r_commit.json()['token'], None)
        self.assertNotEqual(r_commit.json()['expires'], None)
        self.assertEqual(r_commit.json()['user'], account_id)
        self.assertEqual(zulu.parse(r_commit.json()['expires']) > t, True)
        self.assertEqual(
            zulu.parse(r_commit.json()['expires']) > zulu.parse(
                r_init.json()['expires']), True)
        pass
Esempio n. 6
0
    def test_commit_auth_keyid_null(self):
        """
        Test case for commit_auth.
        Tests authentication with keyId that does not exists
        """

        headers = lippuclient.generate_headers(
            account_id=self.testdata['valid_client1'])
        r_init = lippuclient.authentication_init_request(
            self.envdata['base_url'],
            headers=headers,
            account_id=self.testdata['valid_client1'])

        logging.info("test_commit_auth_keyid_null, init response: %s" %
                     r_init.text)
        self.assertEqual(r_init.status_code, 200)
        self.assertNotEqual(r_init.json()['nonce'], None)

        # Commit authentication and receive authentication token.
        headers['X-Message-Id'] = str(uuid.uuid4())
        nonce = str(uuid.uuid4())
        nonces = r_init.json()['nonce'] + nonce
        data = base64.b64encode(nonces.encode()).decode("utf-8")
        commit_body = {
            'data': data,
            'pubKeyId': None,
            'cnonce': nonce,
            'snonce': r_init.json()['nonce'],
            'alg': 'RSA+SHA256'
        }
        r_commit = requests.post(self.envdata['base_url'] +
                                 lippuclient.AUTHENTICATION_COMMIT_ENDPOINT,
                                 headers=headers,
                                 json=commit_body)

        logging.info("test_commit_auth_keyid_not_found, commit response: %s" %
                     r_commit.text)
        self.assertEqual(r_commit.status_code, 400)
        pass
Esempio n. 7
0
 def setUp(self):
     """
     Set up test data for the test cases.
     """
     testdata_file = 'tests/testdata/testdata.json'
     testdata_json = open(testdata_file)
     self.testdata = json.load(testdata_json)
     testdata_json.close()
     env_file = 'tests/env.json'
     env_json = open(env_file)
     target_environment = os.getenv('target_environment', 'test')
     logging.debug("TestProductsApi: Setting target environment: %s",
                   target_environment)
     self.envdata = json.load(env_json)[target_environment]
     env_json.close()
     token = lippuclient.get_authentication_token(
         self.envdata['base_url'], str(uuid.uuid4()),
         self.testdata['valid_client1'], self.testdata['key_id_client1'],
         self.testdata['key_path_client1'])
     self.headers = lippuclient.generate_headers(
         account_id=self.testdata['valid_client1'],
         token=token,
         language="fi")