Exemplo n.º 1
0
    def test_update_passwordmatch_nomatch_field(self, fields, mock_get):
        """ password that doesnt need updating """
        value = [{
            "Password": "******",
            "Title": "bar",
            "UserName": "******",
            "GenericField1": "123",
            "PasswordID": 999
        }]
        mock_get.return_value = mock.Mock(status_code=200, json=lambda: value)

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123', {
            'id': None,
            'field': 'GenericField1',
            'field_id': '123'
        })

        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
Exemplo n.º 2
0
 def test_password(self):
     """ test password getter """
     api = mock.Mock()
     api.update = mock.Mock()
     password = Password()
     password.api = api
     fields = {"password": "******"}
     password.update(fields)
     password.api.update.assert_called_once_with(password, fields)
 def test_password(self):
     """ test password getter """
     api = mock.Mock()
     api.update = mock.Mock()
     password = Password()
     password.api = api
     fields = {"password": "******"}
     password.update(fields)
     password.api.update.assert_called_once_with(password, fields)
Exemplo n.º 4
0
    def test_password(self):
        """ test password getter """
        api = mock.Mock()
        api.get_password_fields = mock.Mock()
        api.get_password_fields.return_value = {"Password": "******"}

        password = Password()
        password.api = api

        self.assertEqual("securepassword", password.password)
    def test_password(self):
        """ test password getter """
        api = mock.Mock()
        api.get_password_fields = mock.Mock()
        api.get_password_fields.return_value = {"Password": "******"}

        password = Password()
        password.api = api

        self.assertEqual("securepassword", password.password)
Exemplo n.º 6
0
    def test_init_exception(self):
        """ test constructor """
        api = mock.Mock()
        list_id = 123

        matcher = {'id': None, 'field': None, 'field_id': None}
        with self.assertRaises(PasswordIdException):
            password = Password(api, list_id, matcher)

        matcher = {}
        with self.assertRaises(PasswordIdException):
            password = Password(api, list_id, matcher)
Exemplo n.º 7
0
    def test_update_newpassword_withtitle(self, mock_urlopen):
        """ password that doesnt need updating """
        mock_urlopen.return_value.read.return_value = '[]'

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123',
                            {'id': None, 'field': 'GenericField1', 'field_id': '123'})

        fields = {'password': '******', 'Title': 'mytitle'}
        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
Exemplo n.º 8
0
    def test_update_passwordmatch_nomatch_id(self, fields, mock_urlopen):
        """ password that doesnt need updating """
        value = '[{"Password": "******", "Title": "bar", ' \
                '"UserName": "******", "GenericField1": "123", ' \
                '"PasswordID": 999}]'
        mock_urlopen.return_value.read.return_value = value

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123',
                            {'id': '999', 'field': None, 'field_id': None})

        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
    def test_update_passwordmatch_nomatch_field(self, fields, mock_urlopen):
        """ password that doesnt need updating """
        value = '[{"Password": "******", "Title": "bar", ' \
                '"UserName": "******", "GenericField1": "123", ' \
                '"PasswordID": 999}]'
        mock_urlopen.return_value.read.return_value = value

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123',
                            {'id': None, 'field': 'GenericField1', 'field_id': '123'})

        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
Exemplo n.º 10
0
    def test_init_passwordid_2(self):
        """ test constructor with password id and field values """
        api = mock.Mock()
        list_id = 123
        matcher = {'id': 987, 'field': 'GenericField1', 'field_id': 'abc'}
        password = Password(api, list_id, matcher)

        self.assertEqual(password.api, api)
        self.assertEqual(password.password_list_id, list_id)
        self.assertEqual(password.password_id, matcher['id'])
        self.assertFalse(hasattr(password, 'field'))
        self.assertFalse(hasattr(password, 'field_id'))
Exemplo n.º 11
0
    def test_init_passwordid_1(self):
        """ test constructor with password id """
        api = mock.Mock()
        list_id = 123
        matcher = {'id': 987, 'field': None, 'field_id': None}
        password = Password(api, list_id, matcher)

        self.assertEqual(password.api, api)
        self.assertEqual(password.password_list_id, list_id)
        self.assertEqual(password.password_id, matcher['id'])
        self.assertFalse(hasattr(password, 'field'))
        self.assertFalse(hasattr(password, 'field_id'))
Exemplo n.º 12
0
    def test_init_field(self):
        """ test constructor """
        api = mock.Mock()
        list_id = 123
        matcher = {'id': None, 'field': 'GenericField1', 'field_id': 'abc'}
        password = Password(api, list_id, matcher)

        self.assertEqual(password.api, api)
        self.assertEqual(password.password_list_id, list_id)
        self.assertEqual(password.match_field, matcher['field'])
        self.assertEqual(password.match_field_id, matcher['field_id'])
        self.assertFalse(hasattr(password, 'password_id'))
Exemplo n.º 13
0
    def test_update_newpassword_notitle(self, mock_get):
        """ password that doesnt need updating """
        mock_get.return_value = mock.Mock(status_code=200, json=lambda: [])

        module = mock.Mock()
        module.fail_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123', {
            'id': None,
            'field': 'GenericField1',
            'field_id': '123'
        })

        fields = {'password': '******'}
        password.update(fields)

        module.fail_json.assert_called_with(
            msg='Title is required when creating passwords')
Exemplo n.º 14
0
 def test_type_field(self):
     """ test logic of password id type """
     password = Password()
     with self.assertRaises(PasswordIdException):
         password.type
Exemplo n.º 15
0
 def test_type_field(self):
     """ test logic of password id type """
     password = Password()
     password.match_field = 'GenericField1'
     password.match_field_id = 'abc'
     self.assertEqual('match_field', password.type)
Exemplo n.º 16
0
 def test_type_passwordid_2(self):
     """ test logic of password id type """
     password = Password()
     password.password_id = 987
     self.assertEqual('password_id', password.type)
 def test_type_passwordid_2(self):
     """ test logic of password id type """
     password = Password()
     password.password_id = 987
     self.assertEqual('password_id', password.type)
 def test_type_field(self):
     """ test logic of password id type """
     password = Password()
     password.match_field = 'GenericField1'
     password.match_field_id = 'abc'
     self.assertEqual('match_field', password.type)