forked from dlindahl/omniauth-cas
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves merge conflict in OmniAuth::Strategies::CAS::SamlTicketValid…
…ator. Adds #success_body loading in OmniAuth::Strategies::CAS::SamlTicketValidator
- Loading branch information
1 parent
b734118
commit be56dcb
Showing
3 changed files
with
222 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<Body> | ||
<Response InResponseTo="clc.example.com" | ||
IssueInstant="2023-11-17T21:55:49.424Z" | ||
MajorVersion="1" | ||
MinorVersion="1" | ||
ResponseID="_fcf43fe7a22512b96095b4a368b26a5f" | ||
xmlns:saml1p="urn:oasis:names:tc:SAML:1.0:protocol" | ||
> | ||
<Status> | ||
<StatusCode Value="saml1p:Success" /> | ||
</Status> | ||
<Assertion | ||
AssertionID="_c2373528d5183c5a981561dc3baf145b" | ||
IssueInstant="2023-11-17T21:55:49.424Z" | ||
Issuer="localhost" | ||
MajorVersion="1" | ||
MinorVersion="1" | ||
xmlns:saml1="urn:oasis:names:tc:SAML:1.0:assertion" | ||
> | ||
<Conditions NotBefore="2023-11-17T21:55:49.424Z" NotOnOrAfter="2023-11-17T21:56:49.424Z"> | ||
<AudienceRestrictionCondition> | ||
<Audience>https://clc.example.com/auth/cas/callback?url=https%3A%2F%2Fclc.example.com%2F</Audience> | ||
</AudienceRestrictionCondition> | ||
</Conditions> | ||
<AuthenticationStatement | ||
AuthenticationInstant="2023-11-17T21:56:19.066Z" | ||
AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" | ||
> | ||
<Subject> | ||
<NameIdentifier>1044957</NameIdentifier> | ||
<SubjectConfirmation> | ||
<ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:artifact</ConfirmationMethod> | ||
</SubjectConfirmation> | ||
</Subject> | ||
</AuthenticationStatement> | ||
<AttributeStatement> | ||
<Subject> | ||
<NameIdentifier>1044957</NameIdentifier> | ||
<SubjectConfirmation> | ||
<ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:artifact</ConfirmationMethod> | ||
</SubjectConfirmation> | ||
</Subject> | ||
<Attribute AttributeName="credentialType" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>UsernamePasswordCredential</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="clientIpAddress" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>192.168.0.5</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="samlAuthenticationStatementAuthMethod" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>urn:oasis:names:tc:SAML:1.0:am:password</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="isFromNewLogin" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>true</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="authenticationDate" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>2023-11-17T21:56:19.066445Z</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="authenticationMethod" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>Static Credentials</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="successfulAuthenticationHandlers" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>Static Credentials</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="serverIpAddress" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>192.168.0.45</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="userAgent" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36</AttributeValue> | ||
</Attribute> | ||
<Attribute AttributeName="longTermAuthenticationRequestTokenUsed" AttributeNamespace="http://www.ja-sig.org/products/cas/"> | ||
<AttributeValue>false</AttributeValue> | ||
</Attribute> | ||
</AttributeStatement> | ||
</Assertion> | ||
</Response> | ||
</Body> | ||
</Envelope> |
113 changes: 113 additions & 0 deletions
113
spec/omniauth/strategies/cas/saml_ticket_validator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
require 'spec_helper' | ||
|
||
describe OmniAuth::Strategies::CAS::SamlTicketValidator do | ||
let(:strategy) do | ||
double('strategy', | ||
service_validate_url: 'https://example.org/serviceValidate' | ||
) | ||
end | ||
let(:provider_options) do | ||
double('provider_options', | ||
disable_ssl_verification?: false, | ||
merge_multivalued_attributes: false, | ||
ca_path: '/etc/ssl/certsZOMG' | ||
) | ||
end | ||
let(:validator) do | ||
OmniAuth::Strategies::CAS::SamlTicketValidator.new( strategy, provider_options, '/foo', nil ) | ||
end | ||
|
||
describe '#call' do | ||
before do | ||
stub_request(:post, 'https://example.org/serviceValidate?') | ||
.to_return(status: 200, body: '') | ||
end | ||
|
||
subject { validator.call } | ||
|
||
it 'returns itself' do | ||
expect(subject).to eq validator | ||
end | ||
|
||
it 'uses the configured CA path' do | ||
subject | ||
expect(provider_options).to have_received :ca_path | ||
end | ||
end | ||
|
||
describe 'called instances' do | ||
let(:ok_fixture) do | ||
File.expand_path(File.join(File.dirname(__FILE__), '../../../fixtures/berkeley_cas_success.xml')) | ||
end | ||
let(:service_response) { File.read(ok_fixture) } | ||
|
||
describe '#success_body' do | ||
before do | ||
stub_request(:post, 'https://example.org/serviceValidate?') | ||
.to_return(status: 200, body: service_response) | ||
validator.call | ||
end | ||
|
||
subject { validator.success_body } | ||
|
||
it 'provides status code' do | ||
expect(subject).to be_an_instance_of Nokogiri::XML::NodeSet | ||
expect(subject.first).to be_an_instance_of Nokogiri::XML::Element | ||
expect(subject.first['Value']).to eq 'saml1p:Success' | ||
end | ||
end | ||
|
||
describe '#user_info' do | ||
before do | ||
stub_request(:post, 'https://example.org/serviceValidate?') | ||
.to_return(status: 200, body: service_response) | ||
validator.call | ||
end | ||
|
||
subject { validator.user_info } | ||
|
||
context 'with default settings' do | ||
it 'parses user info from the response' do | ||
expect(subject).to include 'authenticationDate' => '2023-11-17T21:56:19.066445Z' | ||
expect(subject).to include 'authenticationMethod' => 'Static Credentials' | ||
expect(subject).to include 'clientIpAddress' => '192.168.0.5' | ||
expect(subject).to include 'credentialType' => 'UsernamePasswordCredential' | ||
expect(subject).to include 'isFromNewLogin' => 'true' | ||
expect(subject).to include 'longTermAuthenticationRequestTokenUsed' => 'false' | ||
expect(subject).to include 'nameIdentifier' => '1044957' | ||
expect(subject).to include 'samlAuthenticationStatementAuthMethod' => 'urn:oasis:names:tc:SAML:1.0:am:password' | ||
expect(subject).to include 'serverIpAddress' => '192.168.0.45' | ||
expect(subject).to include 'successfulAuthenticationHandlers' => 'Static Credentials' | ||
expect(subject).to include 'user' => nil | ||
expect(subject).to include 'userAgent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36' | ||
end | ||
end | ||
|
||
context 'when merging multivalued attributes' do | ||
let(:provider_options) do | ||
double('provider_options', | ||
disable_ssl_verification?: false, | ||
merge_multivalued_attributes: true, | ||
ca_path: '/etc/ssl/certsZOMG' | ||
) | ||
end | ||
|
||
it 'parses multivalued user info from the response' do | ||
expect(subject).to include 'authenticationDate' => '2023-11-17T21:56:19.066445Z' | ||
expect(subject).to include 'authenticationMethod' => 'Static Credentials' | ||
expect(subject).to include 'clientIpAddress' => '192.168.0.5' | ||
expect(subject).to include 'credentialType' => 'UsernamePasswordCredential' | ||
expect(subject).to include 'isFromNewLogin' => 'true' | ||
expect(subject).to include 'longTermAuthenticationRequestTokenUsed' => 'false' | ||
expect(subject).to include 'nameIdentifier' => '1044957' | ||
expect(subject).to include 'samlAuthenticationStatementAuthMethod' => 'urn:oasis:names:tc:SAML:1.0:am:password' | ||
expect(subject).to include 'serverIpAddress' => '192.168.0.45' | ||
expect(subject).to include 'successfulAuthenticationHandlers' => 'Static Credentials' | ||
expect(subject).to include 'user' => nil | ||
expect(subject).to include 'userAgent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36' | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |