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)
示例#2
0
 def test_write_read_round_trip(self):
     """
     Test the read and write functions by doing a full round trip test. Save
     some text to a temp file, then read it back, testing both functions at once
     """
     path = "/tmp/" + str(uuid.uuid4())
     expected = str(uuid.uuid4())
     com.write_file(path, expected)
     actual = com.read_file(path)
     os.remove(path)  # cleanup now
     self.assertEqual(expected, actual, "Write-Read round trip")
示例#3
0
    def test_bearer(self):
        """Test a that a token can be returned as a Bearer token"""
        #setup
        token_file = "/tmp/__test_token_file__.txt"
        util.delete_file(token_file)
        expected_token = "file-token"
        expected_bearer = "Bearer " + expected_token
        common.write_file(token_file, expected_token)

        #tests
        options = {'cmr.token.file': token_file}
        actual = str(token.bearer(token.token_file, options))
        self.assertEqual(expected_bearer, actual, "Token formated as Bearer")

        #cleanup
        util.delete_file(token_file)
示例#4
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)