Esempio n. 1
0
    def test_set_token_error(self):
        """ 
        makes a request to the set_token method with the test user. expects an error. 
        """

        with assert_raises(Exception):
            set_token(user='******')
Esempio n. 2
0
    def test_verify_token_ok(self):
        """ makes a new token, and verifies it. expects to get True """

        request_set_token = set_token()
        token = cache.get('token').decode('ASCII')
        verify_token_response = verify_token(token=token)

        logger.debug("verify_token_response: %s", verify_token_response)

        assert_true(verify_token_response)
Esempio n. 3
0
    def test_set_token_ok(self):
        """ 
        makes a request to the set_token method. expects a token and a refresh token to be 
        created and saved in the cache. expect the token is not the same as the refresh token.
        """

        request_set_token = set_token()
        cached_token = cache.get('token').decode('ASCII')
        refreshed_token = cache.get('refresh').decode('ASCII')
        last_verified = cache.get('last_verified')

        logger.debug("token from set_token: %s", cached_token)
        logger.debug("refresh token from set_token: %s", refreshed_token)
        logger.debug("last_verified from set_token: %s", last_verified)

        assert_true(cached_token != refreshed_token)
        assert_true(bool(last_verified))
Esempio n. 4
0
    def test_refresh_token_ok(self):
        """ 
        makes a request to the set_token to create a token. expects a token. calls the refresh
        refresh token with the refreshed_token and expects to get a new token.
        """

        request_set_token = set_token()
        cached_token = cache.get('token').decode('ASCII')
        refreshed_token = cache.get('refresh').decode('ASCII')
        last_verified = cache.get('last_verified')

        logger.debug("token from set_token: %s", cached_token)
        logger.debug("refresh token from set_token: %s", refreshed_token)
        logger.debug("last_verified from set_token: %s", last_verified)

        new_token = refresh_token()
        logger.debug("new_token: %s", new_token)

        assert_true(cached_token != new_token)
        assert_true(bool(last_verified))
Esempio n. 5
0
    def test_get_token_with_invalid_user_no_refresh_token(self):
        """ 
        create a valid token, modify the token and remove the refresher from the cache 
        so they become invalid. change the last_verified so it will get an invalid 
        response from the verify api. expect it to raise an exception at the end.
        """

        token = set_token(
        )  #create a new token, refresher and set last_verified.
        new_token = 'foobar'  # modifing the token so it will become invalid.
        cache.set('token', new_token)  # set the invalid token
        cache.delete('refresh')  # remove the refresh from the cache.
        yesterday_date = datetime.now() + timedelta(
            days=-1)  # move the last_verified one dat back.
        cache.set('last_verified',
                  yesterday_date)  # set the date in the cache.

        # calling the
        #with assert_raises(Exception):
        invalid_token = get_token(user='******')
        logger.debug("invalid token response: %s", invalid_token)

        assert_false(invalid_token)