Skip to content

Commit

Permalink
chore(tests): complete test_keygen_sk_file
Browse files Browse the repository at this point in the history
assert pk file content
  • Loading branch information
hatamiarash7 committed Sep 18, 2024
1 parent 27289cd commit b7a5f8f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/pytests/unit/utils/test_nacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Unit tests for the salt.utils.nacl module
"""

import base64
import os

import nacl as pynacl
import pytest

import salt.modules.config as config
Expand Down Expand Up @@ -59,7 +61,18 @@ def test_keygen_sk_file(test_keygen):
# test sk_file
ret = nacl.keygen(sk_file=fpath)
assert f"saved pk_file: {fpath}.pub" == ret
salt.utils.files.remove(str(fpath) + ".pub")

# test pk_file content with the value of PyNaCl lib
with salt.utils.files.fopen(f"{fpath}.pub", "r") as pkf:
pk = pkf.read()
assert pk != test_keygen["sk"]

sk = base64.b64decode(test_keygen["sk"])
pk_from_pynacl = pynacl.public.PrivateKey(sk)
pk_from_pynacl = base64.b64encode(pk_from_pynacl.public_key.encode())
assert pk.encode() == pk_from_pynacl

salt.utils.files.remove(str(fpath) + ".pub")


def test_keygen_keyfile(test_keygen):
Expand Down

0 comments on commit b7a5f8f

Please sign in to comment.