-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent replays of file server requests
- Loading branch information
Showing
9 changed files
with
171 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Prevent job and fileserver replays |
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
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,54 @@ | ||
""" | ||
tests.pytests.unit.test_crypt | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Unit tests for salt's crypt module | ||
""" | ||
|
||
import uuid | ||
|
||
import pytest | ||
import salt.crypt | ||
import salt.master | ||
import salt.utils.files | ||
|
||
|
||
def test_cryptical_dumps_no_nonce(): | ||
master_crypt = salt.crypt.Crypticle({}, salt.crypt.Crypticle.generate_key_string()) | ||
data = {"foo": "bar"} | ||
ret = master_crypt.dumps(data) | ||
|
||
# Validate message structure | ||
assert isinstance(ret, bytes) | ||
une = master_crypt.decrypt(ret) | ||
une.startswith(master_crypt.PICKLE_PAD) | ||
assert salt.payload.Serial({}).loads(une[len(master_crypt.PICKLE_PAD) :]) == data | ||
|
||
# Validate load back to orig data | ||
assert master_crypt.loads(ret) == data | ||
|
||
|
||
def test_cryptical_dumps_valid_nonce(): | ||
nonce = uuid.uuid4().hex | ||
master_crypt = salt.crypt.Crypticle({}, salt.crypt.Crypticle.generate_key_string()) | ||
data = {"foo": "bar"} | ||
ret = master_crypt.dumps(data, nonce=nonce) | ||
|
||
assert isinstance(ret, bytes) | ||
une = master_crypt.decrypt(ret) | ||
une.startswith(master_crypt.PICKLE_PAD) | ||
nonce_and_data = une[len(master_crypt.PICKLE_PAD) :] | ||
assert nonce_and_data.startswith(nonce.encode()) | ||
assert salt.payload.Serial({}).loads(nonce_and_data[len(nonce) :]) == data | ||
|
||
assert master_crypt.loads(ret, nonce=nonce) == data | ||
|
||
|
||
def test_cryptical_dumps_invalid_nonce(): | ||
nonce = uuid.uuid4().hex | ||
master_crypt = salt.crypt.Crypticle({}, salt.crypt.Crypticle.generate_key_string()) | ||
data = {"foo": "bar"} | ||
ret = master_crypt.dumps(data, nonce=nonce) | ||
assert isinstance(ret, bytes) | ||
with pytest.raises(salt.crypt.SaltClientError, match="Nonce verification error"): | ||
assert master_crypt.loads(ret, nonce="abcde") |
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