| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import pathlib
- import sys
- current = pathlib.Path(__file__)
- test_dir = current.parent
- project_dir = test_dir.parent
- source_dir = project_dir / pathlib.Path("source")
- sys.path.append(str(source_dir))
- import cx_apikey as apikey
- test_count = 0
- def test(tag: str, result: bool) -> None:
- global test_count
- test_count += 1
- print("Running test " + tag + " (" + str(test_count) + "):", end = " ")
- if result:
- print("Valid")
- return
- print("FAIL!!!")
- exit(-1)
- factory = apikey.apikey_factory("test").set_size(15)
- sample = factory.generate()
- sample_manual = "test_1234567890"
- bad_sample = "no_1234567890"
- other_bad = "test_uuuuuuuuuu"
- validator = factory.get_validator()
- test("self generated", validator.validate(sample))
- test("manual writen proof", validator.validate(sample_manual))
- test("bad sample, not validated", not validator.validate(bad_sample))
- test("second bad sample, not validated", not validator.validate(other_bad))
|