Ejemplo n.º 1
0
    def test_token_file_ignoring_comments(self):
        """
        Test a valid login using the password file lambda. The file itself will
        contain comments to be ignored. This test will require that the test be
        able to write to a temp directory
        """
        #setup
        token_file = "/tmp/__test_token_file__.txt"
        util.delete_file(token_file)
        expected_token = "file-token"
        token_file_content = "#ignore this line\n" + expected_token
        common.write_file(token_file, token_file_content)

        #tests
        actual_token = common.read_file(token_file)
        self.assertEqual(token_file_content, actual_token)

        options = {'cmr.token.file': token_file}
        self.assertEqual(expected_token, token.token_file(options))

        actual = str(token.token(token.token_file, options))
        self.assertEqual(expected_token, actual)

        #cleanup
        util.delete_file(token_file)
Ejemplo n.º 2
0
    def test_request_token_two_ways(self, cmd_mock):
        """
        Try to get the token using two different handlers. The file handler
        should fail fall back to the manager which will pass
        """
        options = {'cmr.token.file': "/tmp/__fake-file-never-existed.txt"}
        expected = "Secure-Token"
        cmd_mock.return_value = expected

        # try file first, then manager
        actual = token.token([token.token_manager, token.token_file], options)
        self.assertEqual(expected, actual)

        # try the other way around
        actual = token.token([token.token_file, token.token_manager], options)
        self.assertEqual(expected, actual)
Ejemplo n.º 3
0
    def test_password_manager(self, cmd_mock):
        """ Test a valid login using the password manager """
        expected_token = "Secure-Token"
        options = {}
        cmd_mock.return_value = expected_token
        self.assertEqual(expected_token, token.token_manager(options))

        actual = str(token.token(token.token_manager, options))
        self.assertEqual(expected_token, actual)
Ejemplo n.º 4
0
    def test_token(self, urlopen_mock):
        """ Test that the code can fetch a token request """
        token_lambdas = [token.token_config]
        config = {'cmr.token.value': 'EDL-UToken-Content'}

        # Setup for a good test
        recorded_data_file = util.resolve_full_path(
            '../data/edl/token_good.json')
        urlopen_mock.return_value = valid_cmr_response(recorded_data_file)
        tokens = token.token(token_lambdas, config)
        self.assertEqual('EDL-UToken-Content', tokens, 'access token test')
Ejemplo n.º 5
0
    def test_token_file(self):
        """
        Test a valid login using the password file lambda with caching on. This
        will require that the test be able to write to a temp directory
        """
        #setup
        token_file = "/tmp/__test_token_file__.txt"
        util.delete_file(token_file)
        expected_token = "file-token"
        common.write_file(token_file, expected_token)

        #tests
        options = {'cmr.token.file': token_file}
        self.assertEqual(expected_token, token.token_file(options))

        actual = str(token.token(token.token_file, options))
        self.assertEqual(expected_token, actual)

        actual_token = common.read_file(token_file)
        self.assertEqual(expected_token, actual_token)

        #cleanup
        util.delete_file(token_file)