Skip to content

Commit

Permalink
Add test for open auth algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
jotonedev committed Sep 27, 2024
1 parent 8272bc4 commit c3df4e8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyown/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .open import *
5 changes: 4 additions & 1 deletion pyown/auth/open.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
def ownCalcPass(password: str | int, nonce: str | int) -> str:
__all__ = ["own_calc_pass"]


def own_calc_pass(password: str | int, nonce: str | int) -> str:
"""
Encode the password using the OPEN algorithm.
Source: https://rosettacode.org/wiki/OpenWebNet_password#Python
Expand Down
4 changes: 2 additions & 2 deletions pyown/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pyown.message import *

from .auth.open import ownCalcPass
from .auth.open import own_calc_pass

__all__ = ["OWNClient"]

Expand Down Expand Up @@ -52,7 +52,7 @@ async def _open_auth(self, msg: OWNMessage):
msg = await self.recv()
nonce = msg.tags[0].removeprefix("#")
# Calculate the password
password = ownCalcPass(self.password, nonce)
password = own_calc_pass(self.password, nonce)
# Send the password
await self.send(RawMessage(tags=["#" + password]))
# Receive the response
Expand Down
Empty file added tests/auth/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions tests/auth/test_open.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pyown.auth import own_calc_pass


def test_auth_v1():
password = "12345"
nonce = "844308954"

assert own_calc_pass(password, nonce) == "4294506975"

0 comments on commit c3df4e8

Please sign in to comment.