def test_uninstall_cert():
    """
    Test uninstalling a certificate into the macOS keychain when it's
    already installed
    """
    expected = {
        "changes": {
            "uninstalled": "Friendly Name"
        },
        "comment": "",
        "name": "/path/to/cert.p12",
        "result": True,
    }

    list_mock = MagicMock(return_value=["Friendly Name"])
    friendly_mock = MagicMock(return_value="Friendly Name")
    uninstall_mock = MagicMock(return_value="1 identity imported.")
    with patch.dict(
            keychain.__salt__,
        {
            "keychain.list_certs": list_mock,
            "keychain.get_friendly_name": friendly_mock,
            "keychain.uninstall": uninstall_mock,
        },
    ):
        out = keychain.uninstalled("/path/to/cert.p12", "passw0rd")
        list_mock.assert_called_once_with("/Library/Keychains/System.keychain")
        friendly_mock.assert_called_once_with("/path/to/cert.p12", "passw0rd")
        uninstall_mock.assert_called_once_with(
            "Friendly Name", "/Library/Keychains/System.keychain", None)
        assert out == expected
Exemple #2
0
    def test_uninstall_cert(self):
        '''
            Test uninstalling a certificate into the macOS keychain when it's
            already installed
        '''
        expected = {
            'changes': {
                'uninstalled': 'Friendly Name'
            },
            'comment': '',
            'name': '/path/to/cert.p12',
            'result': True
        }

        list_mock = MagicMock(return_value=['Friendly Name'])
        friendly_mock = MagicMock(return_value='Friendly Name')
        uninstall_mock = MagicMock(return_value='1 identity imported.')
        with patch.dict(
                keychain.__salt__, {
                    'keychain.list_certs': list_mock,
                    'keychain.get_friendly_name': friendly_mock,
                    'keychain.uninstall': uninstall_mock
                }):
            out = keychain.uninstalled('/path/to/cert.p12', 'passw0rd')
            list_mock.assert_called_once_with(
                '/Library/Keychains/System.keychain')
            friendly_mock.assert_called_once_with('/path/to/cert.p12',
                                                  'passw0rd')
            uninstall_mock.assert_called_once_with(
                'Friendly Name', '/Library/Keychains/System.keychain', None)
            self.assertEqual(out, expected)
Exemple #3
0
    def test_uninstalled_cert(self):
        '''
            Test uninstalling a certificate into the OSX keychain when it's not installed
        '''
        expected = {
            'changes': {},
            'comment': 'Friendly Name already uninstalled.',
            'name': '/path/to/cert.p12',
            'result': True
        }

        list_mock = MagicMock(return_value=['Cert2'])
        friendly_mock = MagicMock(return_value='Friendly Name')
        uninstall_mock = MagicMock(return_value='1 identity imported.')
        with patch.dict(keychain.__salt__, {'keychain.list_certs': list_mock,
                                            'keychain.get_friendly_name': friendly_mock,
                                            'keychain.uninstall': uninstall_mock}):
            out = keychain.uninstalled('/path/to/cert.p12', 'passw0rd')
            list_mock.assert_called_once_with('/Library/Keychains/System.keychain')
            friendly_mock.assert_called_once_with('/path/to/cert.p12', 'passw0rd')
            assert not uninstall_mock.called
            self.assertEqual(out, expected)