Ejemplo n.º 1
0
def test_paasta_secret():
    with mock.patch(
            'paasta_tools.cli.cmds.secret._get_secret_provider_for_service',
            autospec=True,
    ) as mock_get_secret_provider_for_service, mock.patch(
            'paasta_tools.cli.cmds.secret.decrypt_secret',
            autospec=True,
    ) as mock_decrypt_secret, mock.patch(
            'paasta_tools.cli.cmds.secret.get_plaintext_input',
            autospec=True,
    ) as mock_get_plaintext_input:
        mock_secret_provider = mock.Mock(secret_dir='/nail/blah')
        mock_get_secret_provider_for_service.return_value = mock_secret_provider
        mock_args = mock.Mock(
            action='add',
            secret_name='theonering',
            service='middleearth',
            clusters='mesosstage',
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            'middleearth', cluster_names='mesosstage')
        mock_secret_provider.write_secret.assert_called_with(
            action='add',
            secret_name='theonering',
            plaintext=mock_get_plaintext_input.return_value,
        )

        mock_args = mock.Mock(
            action='update',
            secret_name='theonering',
            service='middleearth',
            clusters='mesosstage',
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            'middleearth', cluster_names='mesosstage')
        mock_secret_provider.write_secret.assert_called_with(
            action='update',
            secret_name='theonering',
            plaintext=mock_get_plaintext_input.return_value,
        )

        mock_args = mock.Mock(
            action='decrypt',
            secret_name='theonering',
            service='middleearth',
            clusters='mesosstage',
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            'middleearth', cluster_names='mesosstage')
        mock_decrypt_secret.assert_called_with(
            secret_provider=mock_secret_provider,
            secret_name='theonering',
        )
Ejemplo n.º 2
0
def test_paasta_secret():
    with mock.patch(
            "paasta_tools.cli.cmds.secret._get_secret_provider_for_service",
            autospec=True) as mock_get_secret_provider_for_service, mock.patch(
                "paasta_tools.cli.cmds.secret.decrypt_secret",
                autospec=True) as mock_decrypt_secret, mock.patch(
                    "paasta_tools.cli.cmds.secret.get_plaintext_input",
                    autospec=True) as mock_get_plaintext_input, mock.patch(
                        "paasta_tools.cli.cmds.secret._log_audit",
                        autospec=True) as mock_log_audit:
        mock_secret_provider = mock.Mock(secret_dir="/nail/blah")
        mock_get_secret_provider_for_service.return_value = mock_secret_provider
        mock_args = mock.Mock(
            action="add",
            secret_name="theonering",
            service="middleearth",
            clusters="mesosstage",
            shared=False,
            cross_env_motivation="because ...",
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            "middleearth", cluster_names="mesosstage")
        mock_secret_provider.write_secret.assert_called_with(
            action="add",
            secret_name="theonering",
            plaintext=mock_get_plaintext_input.return_value,
            cross_environment_motivation="because ...",
        )
        mock_log_audit.assert_called_with(
            action="add-secret",
            action_details={
                "secret_name": "theonering",
                "clusters": "mesosstage"
            },
            service="middleearth",
        )

        mock_args = mock.Mock(
            action="update",
            secret_name="theonering",
            service="middleearth",
            clusters="mesosstage",
            shared=False,
            cross_env_motivation=None,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            "middleearth", cluster_names="mesosstage")
        mock_secret_provider.write_secret.assert_called_with(
            action="update",
            secret_name="theonering",
            plaintext=mock_get_plaintext_input.return_value,
            cross_environment_motivation=None,
        )
        mock_log_audit.assert_called_with(
            action="update-secret",
            action_details={
                "secret_name": "theonering",
                "clusters": "mesosstage"
            },
            service="middleearth",
        )

        mock_args = mock.Mock(
            action="decrypt",
            secret_name="theonering",
            service="middleearth",
            clusters="mesosstage",
            shared=False,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            "middleearth", cluster_names="mesosstage")
        mock_decrypt_secret.assert_called_with(
            secret_provider=mock_secret_provider, secret_name="theonering")

        mock_args = mock.Mock(
            action="add",
            secret_name="theonering",
            service=None,
            clusters="mesosstage",
            shared=True,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            secret.SHARED_SECRET_SERVICE, cluster_names="mesosstage")
        mock_decrypt_secret.assert_called_with(
            secret_provider=mock_secret_provider, secret_name="theonering")
        mock_log_audit.assert_called_with(
            action="add-secret",
            action_details={
                "secret_name": "theonering",
                "clusters": "mesosstage"
            },
            service="_shared",
        )

        mock_args = mock.Mock(
            action="add",
            secret_name="theonering",
            service=None,
            clusters=None,
            shared=True,
        )
        with raises(SystemExit):
            secret.paasta_secret(mock_args)
Ejemplo n.º 3
0
def test_paasta_secret():
    with mock.patch(
            'paasta_tools.cli.cmds.secret._get_secret_provider_for_service',
            autospec=True,
    ) as mock_get_secret_provider_for_service, mock.patch(
            'paasta_tools.cli.cmds.secret.decrypt_secret',
            autospec=True,
    ) as mock_decrypt_secret, mock.patch(
            'paasta_tools.cli.cmds.secret.get_plaintext_input',
            autospec=True,
    ) as mock_get_plaintext_input, mock.patch(
            'paasta_tools.cli.cmds.secret._log_audit',
            autospec=True,
    ) as mock_log_audit:
        mock_secret_provider = mock.Mock(secret_dir='/nail/blah')
        mock_get_secret_provider_for_service.return_value = mock_secret_provider
        mock_args = mock.Mock(
            action='add',
            secret_name='theonering',
            service='middleearth',
            clusters='mesosstage',
            shared=False,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            'middleearth', cluster_names='mesosstage')
        mock_secret_provider.write_secret.assert_called_with(
            action='add',
            secret_name='theonering',
            plaintext=mock_get_plaintext_input.return_value,
        )
        mock_log_audit.assert_called_with(
            action='add-secret',
            action_details={
                'secret_name': 'theonering',
                'clusters': 'mesosstage',
            },
            service='middleearth',
        )

        mock_args = mock.Mock(
            action='update',
            secret_name='theonering',
            service='middleearth',
            clusters='mesosstage',
            shared=False,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            'middleearth', cluster_names='mesosstage')
        mock_secret_provider.write_secret.assert_called_with(
            action='update',
            secret_name='theonering',
            plaintext=mock_get_plaintext_input.return_value,
        )
        mock_log_audit.assert_called_with(
            action='update-secret',
            action_details={
                'secret_name': 'theonering',
                'clusters': 'mesosstage',
            },
            service='middleearth',
        )

        mock_args = mock.Mock(
            action='decrypt',
            secret_name='theonering',
            service='middleearth',
            clusters='mesosstage',
            shared=False,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            'middleearth', cluster_names='mesosstage')
        mock_decrypt_secret.assert_called_with(
            secret_provider=mock_secret_provider,
            secret_name='theonering',
        )

        mock_args = mock.Mock(
            action='add',
            secret_name='theonering',
            service=None,
            clusters='mesosstage',
            shared=True,
        )
        secret.paasta_secret(mock_args)
        mock_get_secret_provider_for_service.assert_called_with(
            secret.SHARED_SECRET_SERVICE,
            cluster_names='mesosstage',
        )
        mock_decrypt_secret.assert_called_with(
            secret_provider=mock_secret_provider,
            secret_name='theonering',
        )
        mock_log_audit.assert_called_with(
            action='add-secret',
            action_details={
                'secret_name': 'theonering',
                'clusters': 'mesosstage',
            },
            service='_shared',
        )

        mock_args = mock.Mock(
            action='add',
            secret_name='theonering',
            service=None,
            clusters=None,
            shared=True,
        )
        with raises(SystemExit):
            secret.paasta_secret(mock_args)