Net-Google-FederatedLogin
view release on metacpan or search on metacpan
use Test::More tests => 3;
use CGI;
use Test::Mock::LWP;
$Mock_ua->set_isa('LWP::UserAgent');
use Net::Google::FederatedLogin;
my $fl = Net::Google::FederatedLogin->new(claimed_id => 'example@example.com', return_to => 'http://example.com/return');
my %update_mock_response = (
'https://www.google.com/accounts/o8/.well-known/host-meta?hd=example.com' => sub {
$Mock_response->mock(is_success => sub {return 1});
$Mock_response->mock(decoded_content => sub { return q{Link: <https://www.google.com/accounts/o8/site-xrds?ns=2&hd=example.com>; rel="describedby http://reltype.google.com/openid/xrd-op"; type="application/xrds+xml"}})
},
'https://www.google.com/accounts/o8/site-xrds?ns=2&hd=example.com' => sub {
$Mock_response->mock(decoded_content => sub { return q{<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://docs.oasis-open.org/xri/xrd/2009/01#canonicalize-raw-octets" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
</ds:SignedInfo>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIIDLjCCApegAwIBAgIHALrcoAADBTANBgkqhkiG9w0BAQUFADBGMQswCQYDVQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIEludGVybmV0IEF1dGhvcml0eTAeFw0xMDA0MDcwMDAwMDBaFw0xMDA0MDkwMDAwMDBaMFYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRMwEQYDVQQK...
</ds:X509Certificate>
<ds:X509Certificate>
MIICsDCCAhmgAwIBAgIDC2dxMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVTMRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDkwNjA4MjA0MzI3WhcNMTMwNjA3MTk0MzI3WjBGMQswCQYDVQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAG...
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<XRD>
<CanonicalID>example.com</CanonicalID>
<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/server</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
<Type>http://specs.openid.net/extensions/ui/1.0/mode/popup</Type>
<Type>http://specs.openid.net/extensions/ui/1.0/icon</Type>
<Type>http://specs.openid.net/extensions/pape/1.0</Type>
<URI>https://www.google.com/a/example.com/o8/ud?be=o8</URI>
</Service>
<Service priority="0" xmlns:openid="http://namespace.google.com/openid/xmlns">
<Type>http://www.iana.org/assignments/relation/describedby</Type>
<MediaType>application/xrds+xml</MediaType>
<openid:URITemplate>https://www.google.com/accounts/o8/user-xrds?uri={%uri}</openid:URITemplate>
<openid:NextAuthority>hosted-id.google.com</openid:NextAuthority>
</Service>
</XRD>
</xrds:XRDS>}})
},
'https://www.google.com/accounts/o8/user-xrds?uri=http%3A%2F%2Fexample.com%2Fopenid%3Fid%3D108441225163454056756' => sub {
$Mock_response->mock(decoded_content => sub {
return q{<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://docs.oasis-open.org/xri/xrd/2009/01#canonicalize-raw-octets" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
</ds:SignedInfo>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIICgjCC...KdA2EFA==
</ds:X509Certificate>
<ds:X509Certificate>
MIICsDCCAhmgA...dyLU=
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<XRD>
<CanonicalID>http://example.com/openid?id=108441225163454056756</CanonicalID>
<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/signon</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
<URI>https://www.google.com/a/example.com/o8/ud?be=o8</URI>
</Service>
</XRD>
</xrds:XRDS>}})
}
);
$Mock_ua->mock(get => sub {
my $self = shift;
my $url = shift;
die 'Unexpected request URL: ' . $url unless exists $update_mock_response{$url};
$update_mock_response{$url}->();
return $Mock_response;
}
);
my $auth_url = $fl->get_auth_url();
is($auth_url, 'https://www.google.com/a/example.com/o8/ud'
. '?be=o8'
. '&openid.mode=checkid_setup'
. '&openid.ns=http://specs.openid.net/auth/2.0'
( run in 2.342 seconds using v1.01-cache-2.11-cpan-364913b4093 )