This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add random number generator for RDS credentials
This change removes the requirement for RDS credentials and instead allows them to be generated using a simple random string generator.
- Loading branch information
Niall Creech
committed
Jun 16, 2016
1 parent
c348ab7
commit 7d3a5b3
Showing
4 changed files
with
83 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import random | ||
|
||
import unittest | ||
|
||
import entropy | ||
|
||
from bootstrap_cfn import utils | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
|
||
def test_get_random_string_alphanumeric(self): | ||
""" | ||
TestUtils::test_get_random_string: Test getting a random string | ||
""" | ||
no_of_tests = 1000 | ||
min_key_length = 24 | ||
max_key_length = 128 | ||
# Generate some keys and test how random they are | ||
for i in range(no_of_tests): | ||
length = random.randint(min_key_length, max_key_length) | ||
alphanumeric = random.choice([True, False]) | ||
if alphanumeric: | ||
entropy_floor = 0.4 | ||
else: | ||
entropy_floor = 0.5 | ||
random_string = utils.get_random_string(length, alphanumeric=alphanumeric) | ||
string_entropy = entropy.shannon_entropy(random_string) | ||
message = ("TestUtils::test_get_random_string: Test: %s: Generated string length:%s alphanumeric:%s entropy:%s string:%s" | ||
% (i, length, alphanumeric, string_entropy, random_string)) | ||
print(message) | ||
self.assertEqual(len(random_string), length) | ||
self.assertGreater(string_entropy, entropy_floor, message) |