Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Inconsistent value behaviour between generate_token and decode_token for DISABLE_PAYG and COUNTER_SYNC #25

Open
3 tasks done
dmohns opened this issue Nov 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@dmohns
Copy link
Member

dmohns commented Nov 6, 2024

Preflight Checklist

Expected Behavior

Token value and Token Type have a 1:1 relation for DISABLE_PAYG and COUNTER_SYNC. As a user I would expect generate_token and decode_token to have the same interface in terms of how DISABLE_PAYG and COUNTER_SYNC are specified.

Actual Behavior

In generate_token only token_type must be specified. Providing a non-None value yields:

ValueError: A value is not allowed for this token type.

In decode_token both token_type and token_value are returned.

Steps to reproduce

# OpenPAYGO-python
from openpaygo import OpenPAYGOTokenEncoder, TokenType

encoder = OpenPAYGOTokenEncoder()


new_count, final_token = encoder.generate_token(
    secret_key="bc41ec9530f6dac86b1a29ab82edc5fb",
    count=4,
    value=998,
    token_type=TokenType.DISABLE_PAYG,
    starting_code=516959010,
    restricted_digit_set=False,
    extended_token=False,
)

print(f"{new_count=}")
print(f"{final_token=}")

What operating system(s) are you using?

macOS

Additional Information

Suggested solutions:

Change generate_token to allow a token value that matches the provided token type. If none is given, the token value is derived from token_type. If a token type is provided that does not match the token value throw an error explaining the problem.

Alternative solution:

Change decode_token to not return token values for DISABLE_PAYG and COUNTER_SYNC

@dmohns dmohns added the bug Something isn't working label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant