Exemple #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)
Exemple #2
0
    def test_merge_dicts_2(self):
        """ test merge dicts """
        dict1 = {'Foo': 'bar', 'Bar': 'foo'}
        dict2 = {'Foo': 'foobar', 'Foobar': 'Baz'}
        actual = PasswordState._merge_dicts(dict1, dict2)
        expected = {'Foo': 'foobar', 'Bar': 'foo', 'Foobar': 'Baz'}

        self.assertEqual(actual, expected)
    def test_merge_dicts_2(self):
        """ test merge dicts """
        dict1 = {'Foo': 'bar', 'Bar': 'foo'}
        dict2 = {'Foo': 'foobar', 'Foobar': 'Baz'}
        actual = PasswordState._merge_dicts(dict1, dict2)
        expected = {'Foo': 'foobar', 'Bar': 'foo', 'Foobar': 'Baz'}

        self.assertEqual(actual, expected)
Exemple #4
0
 def test_filter_passwords(self):
     """ test filter passwords """
     passwords = [{'GenericField1': 'alpha', 'GenericField2': 'beta'},
                  {'GenericField1': 'charlie', 'GenericField2': 'delta'},
                  {'GenericField1': 'echo', 'GenericField2': 'alpha'}]
     filtered = PasswordState._filter_passwords(passwords, 'GenericField1', 'alpha')
     self.assertEqual(len(filtered), 1)
     self.assertEqual(filtered[0]['GenericField1'], 'alpha')
Exemple #5
0
    def test_init(self):
        """ test constructor """
        module = mock.Mock()
        url = "http://passwordstate"
        api_key = "abc123xyz"
        passwordstate = PasswordState(module, url, api_key)

        self.assertEqual(passwordstate.module, module)
        self.assertEqual(passwordstate.url, url)
        self.assertEqual(passwordstate.api_key, api_key)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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')