-
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.
- Loading branch information
Showing
6 changed files
with
121 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
import fakeredis | ||
from cryptography.hazmat.primitives import serialization | ||
from cryptography.hazmat.primitives.asymmetric import ed25519 | ||
|
||
from aggrec.key_cache import MemoryKeyCache, RedisKeyCache | ||
|
||
|
||
def test_redis_cache(): | ||
key_id = "xyzzy" | ||
public_key = ed25519.Ed25519PrivateKey.generate().public_key() | ||
public_key_pem = public_key.public_bytes( | ||
encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo | ||
) | ||
|
||
redis_client = fakeredis.FakeRedis() | ||
key_cache = RedisKeyCache(redis_client=redis_client, default_ttl=60) | ||
|
||
res = key_cache.get(key_id) | ||
assert res is None | ||
|
||
key_cache.set(key_id, public_key_pem) | ||
|
||
res = key_cache.get(key_id) | ||
assert res == public_key_pem | ||
|
||
|
||
def test_memory_cache(): | ||
key_id = "xyzzy" | ||
public_key = ed25519.Ed25519PrivateKey.generate().public_key() | ||
public_key_pem = public_key.public_bytes( | ||
encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo | ||
) | ||
|
||
key_cache = MemoryKeyCache() | ||
|
||
res = key_cache.get(key_id) | ||
assert res is None | ||
|
||
key_cache.set(key_id, public_key_pem) | ||
|
||
res = key_cache.get(key_id) | ||
assert res == public_key_pem |
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,21 @@ | ||
from cryptography.hazmat.primitives import serialization | ||
from cryptography.hazmat.primitives.asymmetric import ed25519 | ||
from pytest_httpx import HTTPXMock | ||
|
||
from aggrec.key_cache import MemoryKeyCache | ||
from aggrec.key_resolver import UrlKeyResolver | ||
|
||
|
||
def test_url_key_resolver(httpx_mock: HTTPXMock): | ||
key_id = "xyzzy" | ||
public_key = ed25519.Ed25519PrivateKey.generate().public_key() | ||
public_key_pem = public_key.public_bytes( | ||
encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo | ||
) | ||
|
||
httpx_mock.add_response(url=f"https://keys/{key_id}.pem", content=public_key_pem) | ||
|
||
resolver = UrlKeyResolver(client_database_base_url="https://keys", key_cache=MemoryKeyCache()) | ||
|
||
res = resolver.resolve_public_key(key_id) | ||
assert res == public_key |