forked from Netflix/bless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validations for hostnames and tests
- Loading branch information
1 parent
242a586
commit ed85a7f
Showing
10 changed files
with
163 additions
and
18 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
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
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,13 @@ | ||
[Bless Options] | ||
# The default values are sane, these are not. | ||
certificate_validity_after_seconds = 1 | ||
certificate_validity_before_seconds = 1 | ||
entropy_minimum_bits = 2 | ||
random_seed_bytes = 3 | ||
logging_level = DEBUG | ||
|
||
[Bless CA] | ||
us-east-1_password = <INSERT_US-EAST-1_KMS_ENCRYPTED_BASE64_ENCODED_PEM_PASSWORD_HERE> | ||
us-west-2_password = <INSERT_US-WEST-2_KMS_ENCRYPTED_BASE64_ENCODED_PEM_PASSWORD_HERE> | ||
default_password = <INSERT_DEFAULT_KMS_ENCRYPTED_BASE64_ENCODED_PEM_PASSWORD_HERE> | ||
ca_private_key_file = <INSERT_YOUR_ENCRYPTED_PEM_FILE_NAME> |
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
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,49 @@ | ||
import pytest | ||
from bless.request.bless_request import validate_hostname, HOSTNAME_VALIDATION_OPTIONS, BlessHostSchema | ||
from marshmallow import ValidationError | ||
|
||
|
||
@pytest.mark.parametrize("test_input", [ | ||
'thisthat', | ||
'this.that', | ||
]) | ||
def test_validate_hostnames(test_input): | ||
validate_hostname(test_input, HOSTNAME_VALIDATION_OPTIONS.url) | ||
|
||
|
||
@pytest.mark.parametrize("test_input", [ | ||
'this..that', | ||
['thisthat'], | ||
'this!that.com' | ||
]) | ||
def test_invalid_hostnames(test_input): | ||
with pytest.raises(ValidationError) as e: | ||
validate_hostname(test_input, HOSTNAME_VALIDATION_OPTIONS.url) | ||
assert str(e.value) == 'Invalid hostname "ssh://{}".'.format(test_input) | ||
|
||
|
||
@pytest.mark.parametrize("test_input", [ | ||
'this..that', | ||
['thisthat'], | ||
'this!that.com', | ||
'this,that' | ||
]) | ||
def test_invalid_hostnames_with_disabled(test_input): | ||
validate_hostname(test_input, HOSTNAME_VALIDATION_OPTIONS.disabled) | ||
|
||
|
||
@pytest.mark.parametrize("test_input", [ | ||
'thisthat,this.that', | ||
'this.that,thishostname' | ||
]) | ||
def test_valid_multiple_hostnames(test_input): | ||
BlessHostSchema().validate_hostnames(test_input) | ||
|
||
|
||
@pytest.mark.parametrize("test_input", [ | ||
'thisthat, this.that', | ||
]) | ||
def test_invalid_multiple_hostnames(test_input): | ||
with pytest.raises(ValidationError) as e: | ||
BlessHostSchema().validate_hostnames(test_input) | ||
assert str(e.value) == 'Invalid hostname "ssh:// this.that".' |