This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new AuthenticationStrategyInterface
- Loading branch information
Showing
13 changed files
with
84 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ coverage.xml | |
.conjurrc | ||
*.key | ||
*.crt | ||
cleanup.log | ||
|
||
# Build artifacts | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,48 @@ | ||
import unittest | ||
from unittest.mock import mock_open, patch | ||
|
||
from conjur.data_object.conjurrc_data import ConjurrcData | ||
from conjur.data_object import ConjurrcData, AuthnTypes | ||
from conjur.errors import InvalidConfigurationException | ||
|
||
EXPECTED_REP_OBJECT={'conjur_url': 'https://someurl', 'conjur_account': 'someaccount', 'cert_file': "/some/cert/path"} | ||
EXPECTED_CONJURRC = \ | ||
""" | ||
--- | ||
conjur_account: someacc | ||
conjur_url: https://someurl | ||
cert_file: /some/path/to/pem | ||
""" | ||
|
||
CONJURRC_DICT = {'conjur_url': 'https://someurl', 'conjur_account': 'someacc', 'cert_file': '/some/path/to/pem'} | ||
|
||
class ConjurrcDataTest(unittest.TestCase): | ||
|
||
def test_conjurrc_object_representation(self): | ||
conjurrc_data = ConjurrcData("https://someurl", "someaccount", "/some/cert/path") | ||
rep_obj = conjurrc_data.__repr__() | ||
self.assertEquals(str(EXPECTED_REP_OBJECT), rep_obj) | ||
expected_rep_obj = {'conjur_url': 'https://someurl', 'conjur_account': 'someaccount', 'cert_file': "/some/cert/path", 'authn_type': AuthnTypes.AUTHN} | ||
self.assertEquals(str(expected_rep_obj), rep_obj) | ||
|
||
@patch('yaml.load', return_value=CONJURRC_DICT) | ||
input_dict = {'conjur_url': 'https://someurl', 'conjur_account': 'someacc', 'cert_file': '/some/path/to/pem'} | ||
@patch('yaml.load', return_value=input_dict) | ||
def test_conjurrc_object_is_filled_correctly(self, mock_yaml_load): | ||
with patch("builtins.open", mock_open(read_data=EXPECTED_CONJURRC)): | ||
read_data = \ | ||
""" | ||
--- | ||
conjur_account: someacc | ||
conjur_url: https://someurl | ||
cert_file: /some/path/to/pem | ||
""" | ||
expected_dict = {'conjur_url': 'https://someurl', 'conjur_account': 'someacc', 'cert_file': '/some/path/to/pem', 'authn_type': AuthnTypes.AUTHN} | ||
with patch("builtins.open", mock_open(read_data=read_data)): | ||
mock_conjurrc_data = ConjurrcData.load_from_file() | ||
self.assertEquals(mock_conjurrc_data.__dict__, CONJURRC_DICT) | ||
self.assertEquals(mock_conjurrc_data.__dict__, expected_dict) | ||
|
||
@patch('builtins.open', side_effect=KeyError) | ||
def test_conjurrc_throws_error_when_key_is_missing(self, mock_open): | ||
mock_conjurrc = ConjurrcData("https://someurl", "someaccount", "/some/cert/path") | ||
with self.assertRaises(InvalidConfigurationException): | ||
mock_conjurrc.load_from_file() | ||
mock_conjurrc.load_from_file() | ||
|
||
def test_conjurrc_throws_error_when_invalid_authn_type(self): | ||
read_data = \ | ||
""" | ||
--- | ||
conjur_account: someacc | ||
conjur_url: https://someurl | ||
cert_file: /some/path/to/pem | ||
authn_type: abcd | ||
""" | ||
with patch("builtins.open", mock_open(read_data=read_data)): | ||
with self.assertRaises(InvalidConfigurationException) as context: | ||
ConjurrcData.load_from_file() | ||
self.assertRegex(str(context.exception), "Invalid authn_type") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters