Example #1
0
    def test_config_dictionary_has_appropriate_map(self):
        test_data = dict(Config(config_file=self.GOOD_CONJURRC))

        for config_property, config_value in self.EXPECTED_CONFIG.items():
            error_message = "Config field '{}' was '{}' instead of '{}'!".format(
                config_property, test_data[config_property], config_value)
            self.assertEqual(test_data[config_property], config_value,
                             error_message)
Example #2
0
    def test_config_has_appropriate_attributes(self):
        test_data = Config(config_file=self.GOOD_CONJURRC)

        for config_property, config_value in self.EXPECTED_CONFIG.items():
            error_message = "Config attribute '{}' was '{}' instead of '{}'!".format(
                config_property, getattr(test_data, config_property),
                config_value)
            self.assertEqual(getattr(test_data, config_property), config_value,
                             error_message)
Example #3
0
    def test_config_printed_shows_formatted_fields(self):
        test_data = str(Config(config_file=self.GOOD_CONJURRC))

        self.assertRegex(
            test_data,
            re.compile(
                "^config:\n" + "\s+account: accountname\n" +
                "\s+ca_bundle: /cert/file/location\n" +
                "\s+url: https://someurl/somepath\n",
                re.MULTILINE | re.DOTALL,
            ))
Example #4
0
    def test_config_printed_shows_formatted_fields(self):
        test_data = str(
            Config(config_file=self.GOOD_CONJURRC, netrc_file=self.GOOD_NETRC))

        self.assertRegex(
            test_data,
            re.compile(
                "^config:\n" + "\s+account: accountname\n" +
                "\s+api_key: conjurapikey\n" +
                "\s+ca_bundle: /cert/file/location\n" +
                "\s+login_id: someadmin\n" + "\s+plugins:.*foo.*bar.*\n" +
                "\s+url: https://someurl/somepath\n",
                re.MULTILINE | re.DOTALL,
            ))
Example #5
0
 def test_config_with_no_conjurrc_url_raises_error(self):
     with self.assertRaises(AssertionError):
         Config(config_file=self.MISSING_URL_CONJURRC,
                netrc_file=self.GOOD_NETRC)
Example #6
0
 def test_config_with_no_netrc_entry_raises_error(self):
     with self.assertRaises(RuntimeError):
         Config(config_file=self.GOOD_CONJURRC,
                netrc_file=self.MISSING_MACHINE_NETRC)
Example #7
0
 def test_config_with_no_netrc_raises_error(self):
     with self.assertRaises(FileNotFoundError):
         Config(config_file=self.GOOD_CONJURRC, netrc_file='/tmp/bar')
Example #8
0
 def test_config_with_no_conjurrc_raises_error(self):
     with self.assertRaises(FileNotFoundError):
         Config(config_file='/tmp/foo', netrc_file=self.GOOD_NETRC)
Example #9
0
 def test_config_loading_works(self):
     Config(config_file=self.GOOD_CONJURRC, netrc_file=self.GOOD_NETRC)
Example #10
0
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from mock import patch, Mock
import conjur
from conjur.config import Config

config = Config()
api = conjur.new_from_key('login', 'pass', config)
config.account = 'the-account'

def test_roleid():
    role = api.role('some-kind', 'the-id')
    assert role.roleid == 'the-account:some-kind:the-id'

@patch.object(api, 'put')
def test_role_grant_to_without_admin(mock_put):
    role = api.role('some-kind', 'the-id')
    role.grant_to('some-other-role')
    mock_put.assert_called_with(
        '{0}/the-account/roles/some-kind/the-id?members&member={1}'.format(
            config.authz_url,
            'some-other-role'
Example #11
0
 def test_config_with_empty_conjurrc_raises_error(self):
     with self.assertRaises(ConfigurationMissingException):
         Config(config_file=self.MISSING_CONTENT_CONJURRC)
Example #12
0
 def test_config_with_no_conjurrc_url_raises_error(self):
     with self.assertRaises(InvalidConfigurationException):
         Config(config_file=self.MISSING_URL_CONJURRC)