-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added py tests and updated version of hvac dependency
- Loading branch information
Showing
8 changed files
with
357 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
hvac==1.0.2 | ||
hvac==1.1.0 | ||
git+https://github.com/obervinov/logger-package.git@v1.0.1#egg=logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
""" | ||
This module stores fixtures for performing tests. | ||
""" | ||
import pytest | ||
from vault.vault import VaultClient | ||
|
||
|
||
@pytest.fixture(name="name") | ||
def fixture_name(): | ||
"""Returns the project name.""" | ||
return "testapp-1" | ||
|
||
|
||
@pytest.fixture(name="policy_path") | ||
def fixture_policy_path(): | ||
"""Returns the policy path.""" | ||
return "tests/vault/policy.hcl" | ||
|
||
|
||
@pytest.fixture(name="test_data") | ||
def fixture_test_data(): | ||
"""Returns test data for the module.""" | ||
return { | ||
'username': 'user1', | ||
'password': 'qwerty', | ||
'url': 'https://very-important-site.example.com' | ||
} | ||
|
||
|
||
@pytest.fixture(name="test_path") | ||
def fixture_test_path(): | ||
"""Returns test secret path.""" | ||
return "configuration/mysecret" | ||
|
||
|
||
@pytest.fixture(name="configurator_client") | ||
def fixture_configurator_client(name, policy_path): | ||
"""Returns client of the configurator""" | ||
return VaultClient( | ||
url='http://0.0.0.0:8200', | ||
name=name, | ||
policy=policy_path, | ||
new=True | ||
) | ||
|
||
|
||
@pytest.fixture(name="secrets_client") | ||
def fixture_secrets_client(approle, name): | ||
"""Returns the client of the secrets.""" | ||
return VaultClient( | ||
url='http://0.0.0.0:8200', | ||
name=name, | ||
approle=approle | ||
) | ||
|
||
|
||
@pytest.fixture(name="namespace") | ||
def fixture_namespace(configurator_client, name): | ||
"""Returns the namespace.""" | ||
return configurator_client.create_namespace( | ||
name=name | ||
) | ||
|
||
|
||
@pytest.fixture(name="policy") | ||
def fixture_policy(configurator_client, policy_path, name): | ||
"""Returns the policy path.""" | ||
return configurator_client.create_policy( | ||
name=name, | ||
path=policy_path | ||
) | ||
|
||
|
||
@pytest.fixture(name="approle") | ||
def fixture_approle(configurator_client, name, policy): | ||
"""Returns the approle data.""" | ||
return configurator_client.create_approle( | ||
name=name, | ||
path=name, | ||
policy=policy | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
This test is necessary to check how the module works with the configuration of the vault instance. | ||
""" | ||
import pytest | ||
|
||
|
||
@pytest.mark.order(1) | ||
def test_create_namespace(namespace, name): | ||
""" | ||
Testing the creation of a new namespace. | ||
""" | ||
assert namespace == name | ||
assert isinstance(namespace, str) | ||
|
||
|
||
@pytest.mark.order(2) | ||
def test_create_policy(policy): | ||
""" | ||
Testing the creation of a new policy. | ||
""" | ||
assert policy is not None | ||
assert isinstance(policy, str) | ||
|
||
|
||
@pytest.mark.order(3) | ||
def test_create_approle(approle): | ||
""" | ||
Testing the creation of a new approle. | ||
""" | ||
assert isinstance(approle, dict) | ||
assert approle['id'] is not None | ||
assert approle['secret-id'] is not None | ||
assert approle['mount-point'] is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
This test is necessary to check how the module works with the secrets of the vault instance. | ||
""" | ||
import pytest | ||
|
||
|
||
@pytest.mark.order(4) | ||
def test_client_secret(secrets_client): | ||
""" | ||
Testing the client of the vault | ||
""" | ||
assert secrets_client is not None | ||
assert secrets_client.client is not None | ||
|
||
|
||
@pytest.mark.order(5) | ||
def test_write_secret(secrets_client, test_data, test_path): | ||
""" | ||
Testing writing a secret to the vault | ||
""" | ||
for key, value in test_data.items(): | ||
response = secrets_client.write_secret( | ||
path=test_path, | ||
key=key, | ||
value=value | ||
) | ||
assert response['request_id'] | ||
|
||
|
||
@pytest.mark.order(6) | ||
def test_read_secret(secrets_client, test_data, test_path): | ||
""" | ||
Testing reading a secret to the vault | ||
""" | ||
for key, value in test_data.items(): | ||
response = secrets_client.read_secret( | ||
path=test_path, | ||
key=key | ||
) | ||
assert response == value | ||
assert isinstance(response, (dict, str)) | ||
|
||
|
||
@pytest.mark.order(5) | ||
def test_list_secrets(secrets_client, test_path): | ||
""" | ||
Testing checks the reading of the list of secrets from the vault | ||
""" | ||
response = secrets_client.list_secrets( | ||
path=f"{test_path.split('/')[0]}/" | ||
) | ||
assert f"{test_path.split('/')[1]}" in response | ||
assert isinstance(response, list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
path "auth/token/lookup" { | ||
capabilities = ["read"] | ||
} | ||
path "auth/token/renew" { | ||
capabilities = ["update"] | ||
} | ||
path "auth/token/revoke" { | ||
capabilities = ["update"] | ||
} | ||
path "testapp-1/config" { | ||
capabilities = ["read", "list", "update"] | ||
} | ||
path "testapp-1/metadata/configuration/*" { | ||
capabilities = ["read", "list"] | ||
} | ||
path "testapp-1/data/configuration/*" { | ||
capabilities = ["create", "read", "update", "list"] | ||
} |
Oops, something went wrong.