Beispiel #1
0
    def subtest_config_region_with_valid_index(self):

        self.cleanup_default_generated_files()

        valid_index_of_region = str(sorted(REGIONS).index(REGION) + 1)

        # input for interactive prompts - expanding for readability
        stdin = [
            CONFIG_FILENAME,
            util.USER_ID,
            util.TENANT_ID,
            valid_index_of_region,
            'Y',  # generate new keys
            TEMP_DIR,  # key location
            '',  # use default key name
            PASSPHRASE,
            PASSPHRASE,  # confirm passphrase
            'Y'  # write passphrase to config
        ]

        result = self.invoke(
            ['setup', 'config'], input='\n'.join(stdin))

        assert '{}: {}'.format(valid_index_of_region, REGION) in result.output, 'Region list should be correctly formatted'

        test_config = config.from_file(file_location=CONFIG_FILENAME, profile_name='DEFAULT')
        self.validate_config(test_config)

        assert test_config['region'] == REGION

        # clean up config and keys
        self.cleanup_default_generated_files()
Beispiel #2
0
    def subtest_config_invalid_region_by_index_or_name_with_continue(self):

        self.cleanup_default_generated_files()

        for invalid_region in ['-1', '0', '9999', str(len(REGIONS) + 1), 'aaa']:

            # input for interactive prompts - expanding for readability
            stdin = [
                CONFIG_FILENAME,
                util.USER_ID,
                util.TENANT_ID,
                invalid_region,
                'y',  # continue with unrecognized region
                'Y',  # generate new keys
                TEMP_DIR,  # key location
                '',  # use default key name
                PASSPHRASE,
                PASSPHRASE,  # confirm passphrase
                'Y'  # write passphrase to config
            ]

            result = self.invoke(
                ['setup', 'config'], input='\n'.join(stdin))

            assert 'Unrecognized region: {}'.format(invalid_region) in result.output, 'An expected hit should be given'
            assert "Continue with unrecognized region? (Enter 'n' to re-enter region) [y/N]:" in result.output, 'A continue choice should be given'

            test_config = config.from_file(file_location=CONFIG_FILENAME, profile_name='DEFAULT')
            self.validate_config(test_config)

            assert test_config['region'] == invalid_region

            # clean up config and keys
            self.cleanup_default_generated_files()
Beispiel #3
0
    def subtest_config_existing_keys(self):

        self.cleanup_default_generated_files()

        # generate keys
        keys_stdin = [
            PASSPHRASE,  # passphrase
            PASSPHRASE  # confirm passphrase
        ]
        self.invoke(['setup', 'keys', '--output-dir', TEMP_DIR, '--overwrite'],
                    input='\n'.join(keys_stdin))

        # input for interactive prompts - expanding for readability
        stdin = [
            CONFIG_FILENAME,
            util.USER_ID,
            util.TENANT_ID,
            REGION,
            'n',  # use existing keys
            PRIVATE_KEY_FILENAME,  # private key location
            PASSPHRASE,  # passphrase
            'Y'  # write passphrase to config
        ]

        result = self.invoke(['setup', 'config'], input='\n'.join(stdin))

        print('Output: {}'.format(str(result.output)))

        assert 'Config written to' in result.output, 'Config generation script should run until completion'

        test_config = config.from_file(file_location=CONFIG_FILENAME,
                                       profile_name='DEFAULT')
        self.validate_config(test_config)

        print('Config: {}'.format(str(test_config)))

        assert test_config['user'] == util.USER_ID
        assert test_config['tenancy'] == util.TENANT_ID
        assert test_config['region'] == REGION
        assert test_config['pass_phrase'] == PASSPHRASE

        # validate public key
        assert self.validate_public_key_file(PUBLIC_KEY_FILENAME)

        # validate private key w/ passphrase
        assert oci_cli.cli_setup.validate_private_key_passphrase(
            PRIVATE_KEY_FILENAME, PASSPHRASE)

        # clean up config and keys
        self.cleanup_default_generated_files()