def auth_failure(self): with self.client.post(f'/v1/auth/userpass/login/{self.USER_NAME}', json={'password': random_data(16)}, catch_response=True) as r: if r.status_code == 400 and 'invalid username or password' in r.json( )['errors']: r.success() else: r.failure('unexpected response to invalid login')
def populate(host: str, count: int, size: int, cacerts: str, token: str) -> List[str]: s = requests.Session() s.headers = {'X-Vault-Token': token} if cacerts: s.verify = cacerts click.echo('\nChecking Vault KV version...') kv_version = get_kv_version(client=s, host=host) click.echo( click.style(f'Using Vault KV version {kv_version}\n', bold=True, fg='white')) paths = [] with click.progressbar(range(count), label='Creating test keys in Vault') as bar: for _ in bar: path = common.key_path() if kv_version == 1: r = s.post(f'{host}/v1/secret/test/{path}', json={'value': common.random_data(size)}) else: r = s.post(f'{host}/v1/secret/data/test/{path}', json={'data': { 'value': common.random_data(size) }}) if r.status_code >= 400: try: for msg in r.json()['warnings']: click.echo(click.style( f'Error returned by Vault: {msg}', bold=True, fg='yellow'), err=True) except KeyError: pass r.raise_for_status() else: paths.append(path) return paths
def put_kv_secret(self): key = random.choice(self.locust.testdata['keys']) payload = common.random_data(self.locust.testdata['secret_size']) if self.kv_version == 1: self.client.put(f'/v1/secret/test/{key}', json={'value': payload}, name='/v1/secret/test/[key1]/[key2]') else: self.client.put(f'/v1/secret/data/test/{key}', json={'data': { 'value': payload }}, name='/v1/secret/test/[key1]/[key2]')
def populate(host, count, size, token): s = requests.Session() s.headers = {'X-Vault-Token': token} paths = [] with click.progressbar(range(count), label='Creating test keys in Vault') as bar: for _ in bar: path = common.key_path() r = s.post(f'{host}/v1/secret/test/{path}', json={'value': common.random_data(size)}) r.raise_for_status() paths.append(path) return paths
def put_kv_secret(self): path = '/v1/secret/test/%s' % random.choice(self.locust.testdata['keys']) self.client.put(path, json={'value': common.random_data(self.locust.testdata['secret_size'])}, name='/v1/secret/test/[key1]/[key2]')
def _set_password(cls): cls.password = random_data(16) return cls.password
def encrypt_block(self): data = common.random_data(self.locust.testdata['transit_size']) data = base64.b64encode(data.encode()).decode() self.client.post('/v1/transit/encrypt/test', json={'plaintext': data})