Beispiel #1
0
def test_authenticate_cli_passed_credentials_success(secret_mock):
    fortify_auth = FortifyAuth()
    username, password = fortify_auth.authenticate("cli_username",
                                                   "cli_password")

    assert username == "cli_username"
    assert password == "cli_password"
Beispiel #2
0
def test_authenticate_has_credentials_fail(secret_mock):
    # have the config read the following values
    secret_mock.return_value.get.side_effect = [None, None]

    fortify_auth = FortifyAuth()
    result = fortify_auth._has_auth_creds()

    assert result is False
Beispiel #3
0
def test_authenticate_has_credentials_success(secret_mock):
    # have the config read the following values
    secret_mock.return_value.get.side_effect = [
        "config_username", "config_password"
    ]

    fortify_auth = FortifyAuth()
    result = fortify_auth._has_auth_creds()

    assert result is True
Beispiel #4
0
def test_authenticate_read_from_config_success(secret_mock):
    # have the config read the following values
    secret_mock.return_value.get.side_effect = [
        "config_username", "config_password"
    ]
    fortify_auth = FortifyAuth()

    # None, None means no cli passed credentials
    username, password = fortify_auth.authenticate(None, None)

    assert username == "config_username"
    assert password == "config_password"
Beispiel #5
0
def test_authenticate_prompt_user_success(secret_mock, auth_prompt_mock):
    # When
    secret_mock.return_value.get.side_effect = [None, None]
    auth_prompt_mock.return_value = ("prompt_username", "prompt_password")

    # Given
    fortify_auth = FortifyAuth()
    # None, None means no cli passed credentials
    username, password = fortify_auth.authenticate(None, None)

    # Expect
    assert username == "prompt_username"
    assert password == "prompt_password"
Beispiel #6
0
    def __init__(self, username, password, application_name, version_name):
        self.config = FortifyConfig()

        if application_name is None:
            application_name = self.config.application_name

        self.username, self.password = FortifyAuth().authenticate(
            username, password)
        self.download(application_name, version_name)
Beispiel #7
0
def admin_credentials(fortify, webinspect, clear, username, password):
    if fortify:
        fortify_auth = FortifyAuth()
        if clear:
            fortify_auth.clear_credentials()
            fortifyloghelper.log_info_credentials_clear_success()
        else:
            if username and password:
                try:
                    fortify_auth.write_credentials(username, password)
                    loghelper.log_info_credentials_store_success()

                except ValueError:
                    fortifyloghelper.log_error_credentials_not_stored()

            else:
                username, password = auth_prompt("Fortify")
                try:
                    fortify_auth.write_credentials(username, password)
                    loghelper.log_info_credentials_store_success()
                except ValueError:
                    fortifyloghelper.log_error_credentials_not_stored()

    elif webinspect:
        webinspect_auth = WebInspectAuth()
        if clear:
            webinspect_auth.clear_credentials()
            loghelper.log_info_webinspect_credential_clear_success()
        else:
            if username and password:
                try:
                    webinspect_auth.write_credentials(username, password)
                    loghelper.log_info_credentials_store_success()

                except ValueError:
                    fortifyloghelper.log_error_credentials_not_stored()

            else:
                username, password = auth_prompt("WebInspect")
                try:
                    webinspect_auth.write_credentials(username, password)
                    loghelper.log_info_credentials_store_success()

                except ValueError:
                    fortifyloghelper.log_error_credentials_not_stored()
    else:
        sys.stdout.write(
            str("Please specify either the --fortify or --webinspect options,\n"
                "if you wish to re-set your credentals append --clear"))
Beispiel #8
0
    def __init__(self, username, password, application_name, version_name,
                 scan_name, custom_value):
        self.config = FortifyConfig()

        if application_name is None:
            application_name = self.config.application_name
        if not scan_name:
            scan_name = version_name

        self.username, self.password = FortifyAuth().authenticate(
            username, password)
        self.upload(application_name, version_name,
                    self.config.project_template, scan_name, custom_value)
Beispiel #9
0
    def __init__(self, username, password, application_name):
        self.config = FortifyConfig()

        self.username, self.password = FortifyAuth().authenticate(
            username, password)
        self.list(application_name)
Beispiel #10
0
def test_authenticate_clear_credentials_success(secret_mock):
    fortify_auth = FortifyAuth()
    fortify_auth.clear_credentials()

    secret_mock.return_value.clear_credentials.assert_called_once_with(
        'fortify', 'username', 'password')
Beispiel #11
0
def test_authenticate_write_credentials_success(secret_mock):
    fortify_auth = FortifyAuth()
    fortify_auth.write_credentials("some_username", "some_password")

    assert secret_mock.return_value.get.call_count == 2