def test_end_to_end_nosalt(self): splunk_secret = base64.b64encode(os.urandom(255))[:254] plaintext1 = base64.b64encode(os.urandom(255))[:24].decode() ciphertext = splunksecrets.encrypt(splunk_secret, plaintext1, nosalt=True) plaintext2 = splunksecrets.decrypt(splunk_secret, ciphertext, nosalt=True) self.assertEqual(plaintext2, plaintext1)
def test_encrypt_character_matches_salt2(self): ciphertext = splunksecrets.encrypt(splunk_secret, "DEFAULTSA" * 8) self.assertEqual(ciphertext, "$1$681ZK4BL5qRLsmMRT6EotpYVgOge69IZZhhxq0P+2ZBCaRTkci1IwiwRG9Ty2bHaSoG1p9QSXWIYA7mrYsyFqfWYqlvg+oQ+sg==") # noqa: E501
def test_encrypt_character_matches_salt1(self): ciphertext = splunksecrets.encrypt(splunk_secret, "A" * 8) self.assertEqual(ciphertext, "$1$qowYK8EKp+UK")
def test_encrypt_nosalt(self): ciphertext = splunksecrets.encrypt(splunk_secret, "temp1234", nosalt=True) self.assertEqual(ciphertext, "$1$2+1yGuQ1gcMK")
def test_encrypt(self): ciphertext = splunksecrets.encrypt(splunk_secret, "temp1234") self.assertEqual(ciphertext, "$1$n6g0W7F51ZAK")
def test_end_to_end_character_matches_salt(self): splunk_secret = base64.b64encode(os.urandom(255))[:255] plaintext1 = "".join([random.choice("DEFAULTSA") for _ in range(24)]) ciphertext = splunksecrets.encrypt(splunk_secret, plaintext1) plaintext2 = splunksecrets.decrypt(splunk_secret, ciphertext) self.assertEqual(plaintext2, plaintext1)
def test_end_to_end(self): splunk_secret = base64.b64encode(os.urandom(255))[:255] plaintext1 = base64.b64encode(os.urandom(255))[:24].decode() ciphertext = splunksecrets.encrypt(splunk_secret[:16], plaintext1) plaintext2 = splunksecrets.decrypt(splunk_secret[:16], ciphertext) self.assertEqual(plaintext2, plaintext1)
def test_encrypt_raises_value_error_short_secret(self): with self.assertRaises(ValueError): splunk_secret = base64.b64encode(os.urandom(255))[:15] splunksecrets.encrypt(splunk_secret, "temp1234")