aboutsummaryrefslogtreecommitdiffstats
path: root/t/Mock/OpenIDConnect.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2020-09-29 14:23:52 +0200
committerMarius Halden <marius.h@lden.org>2020-09-29 14:23:52 +0200
commita27ce1524d801d2742a2bdb6ec1da45126d64353 (patch)
tree64123c4e17dc1776aa0a7cd65ee01d49d3e7d978 /t/Mock/OpenIDConnect.pm
parent377bd96aab7cad3434185c30eb908c9da447fe40 (diff)
parent2773c60226b9370fe8ee00f7b205b571bb87c3b5 (diff)
Merge tag 'v3.0.1' into fiksgatami-dev
Diffstat (limited to 't/Mock/OpenIDConnect.pm')
-rw-r--r--t/Mock/OpenIDConnect.pm77
1 files changed, 77 insertions, 0 deletions
diff --git a/t/Mock/OpenIDConnect.pm b/t/Mock/OpenIDConnect.pm
new file mode 100644
index 000000000..ba7d03b1d
--- /dev/null
+++ b/t/Mock/OpenIDConnect.pm
@@ -0,0 +1,77 @@
+package t::Mock::OpenIDConnect;
+
+use JSON::MaybeXS;
+use Web::Simple;
+use DateTime;
+use MIME::Base64 qw(encode_base64);
+use MooX::Types::MooseLike::Base qw(:all);
+
+has json => (
+ is => 'lazy',
+ default => sub {
+ JSON->new->pretty->allow_blessed->convert_blessed;
+ },
+);
+
+has returns_email => (
+ is => 'rw',
+ isa => Bool,
+ default => 1,
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /oauth2/v2.0/authorize + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/html' ], [ 'OpenID Connect login page' ] ];
+ },
+
+ sub (GET + /oauth2/v2.0/logout + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/html' ], [ 'OpenID Connect logout page' ] ];
+ },
+
+ sub (POST + /oauth2/v2.0/token + ?*) {
+ my ($self) = @_;
+ my $header = {
+ typ => "JWT",
+ alg => "RS256",
+ kid => "XXXfakeKEY1234",
+ };
+ my $now = DateTime->now->epoch;
+ my $payload = {
+ exp => $now + 3600,
+ nbf => $now,
+ ver => "1.0",
+ iss => "https://login.example.org/12345-6789-4321-abcd-12309812309/v2.0/",
+ sub => "my_cool_user_id",
+ aud => "example_client_id",
+ iat => $now,
+ auth_time => $now,
+ given_name => "Andy",
+ family_name => "Dwyer",
+ tfp => "B2C_1_default",
+ extension_CrmContactId => "1c304134-ef12-c128-9212-123908123901",
+ nonce => 'MyAwesomeRandomValue',
+ };
+ $payload->{emails} = ['pkg-tappcontrollerauth_socialt-oidc@example.org'] if $self->returns_email;
+ my $signature = "dummy";
+ my $id_token = join(".", (
+ encode_base64($self->json->encode($header), ''),
+ encode_base64($self->json->encode($payload), ''),
+ encode_base64($signature, '')
+ ));
+ my $data = {
+ id_token => $id_token,
+ token_type => "Bearer",
+ not_before => $now,
+ id_token_expires_in => 3600,
+ profile_info => encode_base64($self->json->encode({}), ''),
+ };
+ my $json = $self->json->encode($data);
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+}
+
+__PACKAGE__->run_if_script;