Trog-Routes-JSON.t 1.1 KB

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env perl
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. use Test::More;
  6. use JSON::Validator ();
  7. use FindBin::libs;
  8. require_ok('Trog::Routes::JSON') or BAIL_OUT("Can't find SUT");
  9. subtest 'the change request token is a uuid, and nothing else' => sub {
  10. no warnings 'once';
  11. my ($token) = @{ $Trog::Routes::JSON::routes{'/api/auth_change_request/{token}'}{parameters} };
  12. my $jv = JSON::Validator->new->schema( $token->{schema} );
  13. my $valid = sub ($value) { return !$jv->validate($value) };
  14. ok( $valid->('5bed1745-4201-40dd-b5dd-65acc0316604'), 'a uuid is a token' );
  15. ok( !$valid->(q{}), 'nothing is not' );
  16. ok( !$valid->('x;drop table user'), 'and neither is text with a hex digit in it' );
  17. ok( !$valid->("5bed1745-4201\n"), 'nor a token with something after it' );
  18. ok( !$valid->("5bed1745-4201-40dd-b5dd-65acc0316604\n"), 'nor a uuid with a newline after it' );
  19. ok( !$valid->('a|b'), 'nor a pipe, which the class used to hold' );
  20. };
  21. done_testing();