Skip to content

Commit

Permalink
[#293] use secrets stlib module & regenerate test tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyBA committed Dec 4, 2024
1 parent f411395 commit f3badb1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 38 deletions.
5 changes: 2 additions & 3 deletions src/openklant/components/token/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import binascii
import os
import secrets

from typing import Iterable


def _generate_token() -> str:
return binascii.hexlify(os.urandom(20)).decode()
return secrets.token_hex(20)


def get_token(existing_tokens: Iterable[str]) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ tokens_config_enable: true
tokens_config:
items:
- identifier: token-1
token: 06c76243e011f788c069e0436e529c10b7753609
token: 18b2b74ef994314b84021d47b9422e82b685d82f
contact_person: Person 1
email: [email protected]
organization: Organization XYZ
application: Application XYZ
administration: Administration XYZ

- identifier: token-3
token: 90fd511f069605ace65b32143d0b7e3554054792
token: e882642bd0ec2482adcdc97258c2e6f98cb06d85
contact_person: Person 3
email: [email protected]
organization: Organization ZYX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ tokens_config_enable: true
tokens_config:
items:
- identifier: token-1
token: 06c76243e011f788c069e0436e529c10b7753609
token: 7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799
contact_person: Person 1
email: [email protected]

- identifier: token-2
token: 90fd511f069605ace65b32143d0b7e3554054792
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
contact_person: Person 2
email: [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ tokens_config_enable: true
tokens_config:
items:
- identifier: token-1
token: 06c76243e011f788c069e0436e529c10b7753609
token: 18b2b74ef994314b84021d47b9422e82b685d82f
contact_person: Person 1
email: [email protected]

- identifier: token-3
token: 90fd511f069605ace65b32143d0b7e3554054792
token: e882642bd0ec2482adcdc97258c2e6f98cb06d85
contact_person: Person 3
email: [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ tokens_config_enable: true
tokens_config:
items:
- identifier: token-1
token: 06c76243e011f788c069e0436e529c10b7753609
token: 7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799
contact_person: Person 1
email: [email protected]
organization: Organization XYZ
application: Application XYZ
administration: Administration XYZ

- identifier: token-2
token: 90fd511f069605ace65b32143d0b7e3554054792
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
contact_person: Person 2
email: [email protected]
organization: Organization ZYX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ tokens_config_enable: true
tokens_config:
items:
- identifier: token-1
token: 06c76243e011f788c069e0436e529c10b7753609
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
contact_person: Person 1
email: invalid
organization: Organization XYZ
application: Application XYZ
administration: Administration XYZ

- identifier: token-2
token: 90fd511f069605ace65b32143d0b7e3554054792
token: 795cb35c930d27b98297df761f0fa52182348875
contact_person: Person 2
email: [email protected]
organization: Organization ZYX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ tokens_config_enable: true
tokens_config:
items:
- identifier: foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar
token: 06c76243e011f788c069e0436e529c10b7753609
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
contact_person: Person 1
email: [email protected]
organization: Organization XYZ
application: Application XYZ
administration: Administration XYZ

- identifier: token-2
token: 90fd511f069605ace65b32143d0b7e3554054792
token: 795cb35c930d27b98297df761f0fa52182348875
contact_person: Person 2
email: [email protected]
organization: Organization ZYX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tokens_config:
administration: Administration XYZ

- identifier: token-2
token: 90fd511f069605ace65b32143d0b7e3554054792
token: ba9d233e95e04c4a8a661a27daffe7c9bd019067
contact_person: Person 2
email: [email protected]
organization: Organization ZYX
Expand Down
44 changes: 22 additions & 22 deletions src/openklant/setup_configuration/tests/test_token_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_empty_database(self):

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "06c76243e011f788c069e0436e529c10b7753609"
first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
Expand All @@ -38,7 +38,7 @@ def test_empty_database(self):

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "90fd511f069605ace65b32143d0b7e3554054792"
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
Expand All @@ -49,14 +49,14 @@ def test_empty_database(self):
def test_existing_tokens(self):
TokenAuthFactory(
identifier="token-1",
token="877caee40349810d47c762882085cb46fc7b4786",
token="ba9d233e95e04c4a8a661a27daffe7c9bd019067",
contact_person="Person 4",
email="[email protected]",
)

TokenAuthFactory(
identifier="token-2",
token="03032ceb4352020fa84355a4a4652978942c496d",
token="795cb35c930d27b98297df761f0fa52182348875",
contact_person="Person 2",
email="[email protected]",
)
Expand All @@ -73,7 +73,7 @@ def test_existing_tokens(self):

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "06c76243e011f788c069e0436e529c10b7753609"
first_token.token, "18b2b74ef994314b84021d47b9422e82b685d82f"
)
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
Expand All @@ -85,7 +85,7 @@ def test_existing_tokens(self):

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "03032ceb4352020fa84355a4a4652978942c496d"
second_token.token, "795cb35c930d27b98297df761f0fa52182348875",
)
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
Expand All @@ -97,7 +97,7 @@ def test_existing_tokens(self):

self.assertEqual(third_token.identifier, "token-3")
self.assertEqual(
third_token.token, "90fd511f069605ace65b32143d0b7e3554054792"
third_token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85"
)
self.assertEqual(third_token.contact_person, "Person 3")
self.assertEqual(third_token.email, "[email protected]")
Expand All @@ -108,7 +108,7 @@ def test_existing_tokens(self):
def test_with_all_fields(self):
TokenAuthFactory(
identifier="token-1",
token="877caee40349810d47c762882085cb46fc7b4786",
token="7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799",
contact_person="Person 4",
email="[email protected]",
application="[email protected]",
Expand All @@ -118,7 +118,7 @@ def test_with_all_fields(self):

TokenAuthFactory(
identifier="token-2",
token="03032ceb4352020fa84355a4a4652978942c496d",
token="ba9d233e95e04c4a8a661a27daffe7c9bd019067",
contact_person="Person 2",
email="[email protected]",
)
Expand All @@ -135,7 +135,7 @@ def test_with_all_fields(self):

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "06c76243e011f788c069e0436e529c10b7753609"
first_token.token, "18b2b74ef994314b84021d47b9422e82b685d82f"
)
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
Expand All @@ -147,7 +147,7 @@ def test_with_all_fields(self):

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "03032ceb4352020fa84355a4a4652978942c496d"
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
Expand All @@ -159,7 +159,7 @@ def test_with_all_fields(self):

self.assertEqual(third_token.identifier, "token-3")
self.assertEqual(
third_token.token, "90fd511f069605ace65b32143d0b7e3554054792"
third_token.token, "e882642bd0ec2482adcdc97258c2e6f98cb06d85"
)
self.assertEqual(third_token.contact_person, "Person 3")
self.assertEqual(third_token.email, "[email protected]")
Expand All @@ -170,7 +170,7 @@ def test_with_all_fields(self):
def test_invalid_email(self):
TokenAuthFactory(
identifier="token-1",
token="03032ceb4352020fa84355a4a4652978942c496d",
token="7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799",
contact_person="Person 4",
email="[email protected]",
)
Expand All @@ -188,7 +188,7 @@ def test_invalid_email(self):

self.assertEqual(token.identifier, "token-1")
self.assertEqual(
token.token, "03032ceb4352020fa84355a4a4652978942c496d"
token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(token.contact_person, "Person 4")
self.assertEqual(token.email, "[email protected]")
Expand All @@ -199,7 +199,7 @@ def test_invalid_email(self):
def test_invalid_token(self):
TokenAuthFactory(
identifier="token-1",
token="03032ceb4352020fa84355a4a4652978942c496d",
token="7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799",
contact_person="Person 4",
email="[email protected]",
)
Expand All @@ -217,7 +217,7 @@ def test_invalid_token(self):

self.assertEqual(token.identifier, "token-1")
self.assertEqual(
token.token, "03032ceb4352020fa84355a4a4652978942c496d"
token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(token.contact_person, "Person 4")
self.assertEqual(token.email, "[email protected]")
Expand All @@ -228,7 +228,7 @@ def test_invalid_token(self):
def test_invalid_identifier(self):
TokenAuthFactory(
identifier="token-1",
token="877caee40349810d47c762882085cb46fc7b4786",
token="7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799",
contact_person="Person 4",
email="[email protected]",
)
Expand All @@ -246,7 +246,7 @@ def test_invalid_identifier(self):

self.assertEqual(token.identifier, "token-1")
self.assertEqual(
token.token, "877caee40349810d47c762882085cb46fc7b4786"
token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(token.contact_person, "Person 4")
self.assertEqual(token.email, "[email protected]")
Expand All @@ -267,7 +267,7 @@ def test_idempotent_step(self):

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "06c76243e011f788c069e0436e529c10b7753609"
first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
Expand All @@ -279,7 +279,7 @@ def test_idempotent_step(self):

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "90fd511f069605ace65b32143d0b7e3554054792"
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
Expand All @@ -295,7 +295,7 @@ def test_idempotent_step(self):

self.assertEqual(first_token.identifier, "token-1")
self.assertEqual(
first_token.token, "06c76243e011f788c069e0436e529c10b7753609"
first_token.token, "7b2b212d9f16d171a70a1d927cdcfbd5ca7a4799"
)
self.assertEqual(first_token.contact_person, "Person 1")
self.assertEqual(first_token.email, "[email protected]")
Expand All @@ -307,7 +307,7 @@ def test_idempotent_step(self):

self.assertEqual(second_token.identifier, "token-2")
self.assertEqual(
second_token.token, "90fd511f069605ace65b32143d0b7e3554054792"
second_token.token, "ba9d233e95e04c4a8a661a27daffe7c9bd019067"
)
self.assertEqual(second_token.contact_person, "Person 2")
self.assertEqual(second_token.email, "[email protected]")
Expand Down

0 comments on commit f3badb1

Please sign in to comment.