Google token decoding test
Errietta Kostala [Wed, 28 Jan 2015 10:32:15 +0000 (10:32 +0000)]
stemmaweb_tests.conf
t/07google.t
t/etc/certs [new file with mode: 0644]

index a4e4302..5f796e9 100644 (file)
@@ -1,3 +1,7 @@
 <Registration>
     no_recaptcha 1
 </Registration>
+<Authentication::Credential::Google>
+    public_cert_url file://__path_to(t/etc/certs)__
+    client_id 577442226093-pi2ud795g49ibip78bgfoabhl4kdrguc.apps.googleusercontent.com
+</Authentication::Credential::Google>
index 76ee9ed..46e6a20 100644 (file)
@@ -173,4 +173,50 @@ my $ua = Test::WWW::Mechanize->new;
     $ua->content_contains('Hello! 2!', 'We are logged in.');
 }
 
+# Decoding token
+
+{
+    my $scope = $dir->new_scope;
+
+    ok !$dir->find_user({ sub => 4242, openid_id => 'https://www.google.com/accounts/o8/id3' }), 'The G+ user is not yet there.';
+
+    $ua->get('/logout');
+
+    $ua->get_ok('http://localhost/login');
+
+    $ua->submit_form(
+        form_number => 1,
+        fields => {
+            id_token => 'eyJraWQiOiJhIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI0MjQyIiwib3BlbmlkX2lkIjoiaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS9hY2NvdW50cy9vOC9pZDMifQ.moNERe3UHCY4xGMPxdCqmbg2JKW5feVnYlA8jeB4CdE4c_KL3YHvICQeql-S486HT-AlWBeDJWMr6wWH1kkwz11a2D1oyJ8qCWBssHIkhfv8dm3dphmRbtzYssAOFdGsmnPH1oXolCnl-Qu9WgHkhYYnRJWHr3CkeNA6Yh1xOV3nkaa8REtJckuzh3jyKQgx_rjIFsWBPDmT1rqa_Q0XOGVK34N5tADwpcWmkb3fFnbddzd9L6MnybbFzF_S238Bpr5vNa9doXRBwvJ85AdSn1AWX8R6qVpDbbaiGL2RCahuZYF9XECYm6anee-KTKvxh02KXkG2zniKVvweaMlcbQ',
+            email    => 'email@example.org',
+        },
+    );
+
+    $ua->content_contains('You have logged in.', 'We can now log in to our created user - the token was decoded');
+
+    $ua->get('/');
+
+    $ua->content_contains('Hello! 4242!', 'We are logged in.');
+
+    ok $dir->find_user({ sub => 4242, openid_id => 'https://www.google.com/accounts/o8/id3' }), 'The G+ user is there.';
+
+    $ua->get('/logout');
+
+    $ua->get_ok('http://localhost/login');
+
+    $ua->submit_form(
+        form_number => 1,
+        fields => {
+            id_token => 'eyJraWQiOiJhIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI0MjQyIiwib3BlbmlkX2lkIjoiaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS9hY2NvdW50cy9vOC9pZDMifQ.moNERe3UHCY4xGMPxdCqmbg2JKW5feVnYlA8jeB4CdE4c_KL3YHvICQeql-S486HT-AlWBeDJWMr6wWH1kkwz11a2D1oyJ8qCWBssHIkhfv8dm3dphmRbtzYssAOFdGsmnPH1oXolCnl-Qu9WgHkhYYnRJWHr3CkeNA6Yh1xOV3nkaa8REtJckuzh3jyKQgx_rjIFsWBPDmT1rqa_Q0XOGVK34N5tADwpcWmkb3fFnbddzd9L6MnybbFzF_S238Bpr5vNa9doXRBwvJ85AdSn1AWX8R6qVpDbbaiGL2RCahuZYF9XECYm6anee-KTKvxh02KXkG2zniKVvweaMlcbQ',
+            email   => 'email@example.org',
+        },
+    );
+
+    $ua->content_contains('You have logged in.', 'We can login again');
+
+    $ua->get('/');
+
+    $ua->content_contains('Hello! 4242!', 'We are logged in.');
+}
+
 done_testing;
diff --git a/t/etc/certs b/t/etc/certs
new file mode 100644 (file)
index 0000000..a44c046
--- /dev/null
@@ -0,0 +1,2 @@
+{"a":"-----BEGIN CERTIFICATE-----\nMIIE0DCCArigAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJVUzEL\nMAkGA1UECAwCTUQxEjAQBgNVBAcMCUJhbHRpbW9yZTEQMA4GA1UEAwwHVGVzdCBD\nQTEfMB0GCSqGSIb3DQEJARYQdGVzdEBleGFtcGxlLmNvbTAeFw0xNTAxMjYxMTU3\nNT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