Пример #1
0
    def test_advanced_auth_pass_no_store(self):
        name = "advanced_auth_pass_no_store"
        fail = False
        child, lines = custom_setup(name)

        try:
            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter auth type")
            child.sendline(next(lines))

            child.expect("Config created but no credentials saved")
        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail(
                "pexpect failure - check input tokens, expected output, credentials"
            )
        if not utils.configs_equal(name):
            self.fail("configs are not equal")
Пример #2
0
    def test_advanced_auth_bad_inputs_fail(self):
        name = "advanced_auth_bad_inputs"
        fail = False
        child, lines = custom_setup(name)

        try:
            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter directory")
            child.sendline(next(lines))

            child.expect("Please enter cache strategy")
            child.sendline(next(lines))

            child.expect("Please enter cache age")
            child.sendline(next(lines))

            child.expect("Error. Unable to parse age.")
            child.sendline(next(lines))

            child.expect(
                "Invalid option. Please select between '1' and '8' or leave it empty to use default one"
            )
            child.sendline(next(lines))

            child.expect("Please enter username")
            child.sendline(next(lines))

            child.expect("Blank input is invalid")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter password")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect(pexpect.EOF)

        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail()
Пример #3
0
    def test_advanced_auth_pass_prod(self):
        """"Uses the --dev flag to specify a different domain."""
        name = "advanced_auth_pass_prod"
        fail = False
        child, lines = custom_setup(name)

        try:
            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please choose domain")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter directory")
            child.sendline(next(lines))

            child.expect("Please enter cache strategy")
            child.sendline(next(lines))

            child.expect("Please enter auth type")
            child.sendline(next(lines))

            child.expect("Please enter username")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter password")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect(pexpect.EOF)
        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail(
                "pexpect failure - check input tokens, expected output, credentials"
            )
        if not utils.configs_equal(name):
            self.fail("configs are not equal")
Пример #4
0
    def test_advanced_auth_fail(self):
        name = "advanced_auth_fail"
        fail = False
        child, lines = custom_setup(name)

        try:
            child.expect("Found an existing cli-config")
            child.sendline(next(lines))

            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter directory")
            child.sendline(next(lines))

            child.expect("Please enter cache strategy")
            child.sendline(next(lines))

            child.expect("Please enter auth type")
            child.sendline(next(lines))

            child.expect("Please enter username")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter password")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Failed to authenticate, restoring previous config.")
            child.expect(pexpect.EOF)
        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail()
Пример #5
0
def custom_setup(name: str):
    """
    Returns a tuple - an instance of a child process and an iterable of input tokens for each line 
    for the CLI program.

    Since the builtin setUp() hook does not return anything, one needs to use a custom function 
    instead and call it explicitly inside each test case to retrieve the returned value.
    """
    f = open(f"input/{name}")
    lines = iter(f.read().splitlines())
    f.close()

    cmd = utils.replace_with_env_var(append_test_arguments(name, next(lines)))
    print("running command {}".format(cmd))
    child = popen_spawn.PopenSpawn(cmd)
    child.timeout = utils.timeout

    log_pexpect = os.getenv("LOG_PEXPECT")
    if log_pexpect and log_pexpect.lower() == "true":
        child.logfile = open("init_test_output.txt", "ab")

    return child, lines
Пример #6
0
    def test_advanced_auth_aws_fail(self):
        name = "advanced_auth_aws_fail"
        fail = False
        child, lines = custom_setup(name)

        try:
            child.expect("Found an existing cli-config")
            child.sendline(next(lines))

            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter directory")
            child.sendline(next(lines))

            child.expect("Please enter cache strategy")
            child.sendline(next(lines))

            child.expect("Please enter auth type")
            child.sendline(next(lines))

            child.timeout = 21
            child.expect("Please enter aws profile for federated aws auth")
            child.sendline(next(lines))

            child.expect("Failed to authenticate")
            child.expect(pexpect.EOF)

        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail()
Пример #7
0
    def test_advanced_wrong_store_fail(self):
        name = "advanced_wrong_store_fail"
        fail = False
        child, lines = custom_setup(name)

        try:
            child.expect("Found an existing cli-config")
            child.sendline(next(lines))

            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            # If run on Linux, should fail.
            child.expect("Failed to get store")
            child.expect(pexpect.EOF)
        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail()
Пример #8
0
    def test_advanced_auth_win_cred_pass(self):
        folder = "win_init"
        step_1 = "1_advanced_auth_win_cred_pass"
        step_2 = "2_secret_create"
        step_3 = "3_secret_read"
        step_4 = "4_secret_delete"
        step_5 = "5_cli_config_read"
        step_6 = "6_cli_config_clear"
        fail = False

        secret_path = utils.create_secret_file()
        os.environ["INIT_SECRET_PATH"] = secret_path.replace("\\", "-")
        os.environ["INIT_SECRET_FILE"] = "@{}".format(secret_path)
        child, lines = custom_setup("{}/{}".format(folder, step_1))

        try:
            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter cache strategy")
            child.sendline(next(lines))

            child.expect("Please enter cache age")
            child.sendline(next(lines))

            child.expect("Please enter auth type")
            child.sendline(next(lines))

            child.expect("Please enter username")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter password")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect(pexpect.EOF)

            # create a secret
            child, lines = custom_setup("{}/{}".format(folder, step_2))
            child.timeout = utils.timeout
            child.expect("attributes")
            child.expect(pexpect.EOF)

            # read a secret and cache it
            child, lines = custom_setup("{}/{}".format(folder, step_3))
            child.timeout = utils.timeout
            child.expect("data")
            child.expect(pexpect.EOF)

            # delete a secret and clear it from the cache
            child, lines = custom_setup("{}/{}".format(folder, step_4))
            child.timeout = utils.timeout
            child.expect(pexpect.EOF)

            # read the local config
            child, lines = custom_setup("{}/{}".format(folder, step_5))
            child.timeout = utils.timeout
            child.expect("default")
            child.expect(pexpect.EOF)

            # clear the local config
            child, lines = custom_setup("{}/{}".format(folder, step_6))
            child.timeout = utils.timeout
            child.expect("Are you sure you want to delete CLI configuration")
            child.sendline(next(lines))
            child.expect(pexpect.EOF)

        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail(
                "pexpect failure - check input tokens, expected output, credentials"
            )

        os.environ.unsetenv("INIT_SECRET_PATH")
        os.environ.unsetenv("INIT_SECRET_FILE")
Пример #9
0
    def test_advanced_auth_config_edit(self):
        folder = "config_edit"
        step_1 = "1_config_edit_setup"
        step_2 = "2_config_edit_pass"
        step_3 = "3_config_edit_fail"
        step_4 = "4_cli_config_clear"
        fail = False

        try:
            child, lines = custom_setup("{}/{}".format(folder, step_1))
            child.expect("Please enter tenant name")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter store type")
            child.sendline(next(lines))

            child.expect("Please enter directory")
            child.sendline(next(lines))

            child.expect("Please enter cache strategy")
            child.sendline(next(lines))

            child.expect("Please enter auth type")
            child.sendline(next(lines))

            child.expect("Please enter username")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect("Please enter password")
            child.sendline(utils.replace_with_env_var(next(lines)))

            child.expect(pexpect.EOF)

            # edit the config file without making changes
            child, lines = custom_setup("{}/{}".format(folder, step_2))
            child.timeout = utils.timeout

            child.expect("permissionDocument")
            child.sendcontrol("x")
            child.expect("Data not modified")

            child.expect(pexpect.EOF)

            # edit the config file and make non-JSON changes
            child, lines = custom_setup("{}/{}".format(folder, step_3))
            child.timeout = utils.timeout

            child.expect("permissionDocument")
            child.send("not-actual-json")
            child.sendcontrol("x")
            child.sendline("y")
            child.sendcontrol("m")
            # cli re-opens nano on failure, so exit again
            child.sendcontrol("x")
            child.expect("400")

            child.expect(pexpect.EOF)

            # clear the local config
            child, lines = custom_setup("{}/{}".format(folder, step_4))
            child.timeout = utils.timeout
            child.expect("Are you sure you want to delete CLI configuration")
            child.sendline(next(lines))
            child.expect(pexpect.EOF)

        except pexpect.ExceptionPexpect as ex:
            print(ex.get_trace())
            fail = True

        if fail:
            self.fail(
                "pexpect failure - check input tokens, expected output, credentials"
            )