-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
317f969
commit 6031033
Showing
4 changed files
with
80 additions
and
6 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
defmodule ShinTest.OIDCTest do | ||
defmodule ShinAuth.OIDCTest do | ||
import Mox | ||
|
||
use ExSpec, async: true | ||
|
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,68 @@ | ||
defmodule ShinAuth.SAML.RequestTest do | ||
use ExSpec, async: true | ||
|
||
alias ShinAuth.SAML | ||
alias ShinAuth.SAML.Request | ||
|
||
describe "with malformed saml request" do | ||
context "with empty xml" do | ||
it "returns error" do | ||
{:error, | ||
%Request.Error{ | ||
tag: :malformed_saml_request, | ||
message: "Verify if the SAML request is structured correctly by the Service Provider." | ||
}} = SAML.decode_saml_request("") | ||
end | ||
end | ||
|
||
context "with malformed xml element" do | ||
it "returns error" do | ||
{:error, | ||
%Request.Error{ | ||
tag: :malformed_saml_request, | ||
message: "Verify if the SAML request is structured correctly by the Service Provider." | ||
}} = | ||
SAML.decode_saml_request(""" | ||
<Invalid | ||
""") | ||
end | ||
end | ||
|
||
context "when missing saml request required element" do | ||
saml_request_mock = """ | ||
<?xml version="1.0"?> | ||
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_123" Version="2.0" IssueInstant="2023-09-27T17:20:42.746Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Destination="https://accounts.google.com/o/saml2/idp?idpid=C03gu405z" AssertionConsumerServiceURL="https://auth.example.com/sso/saml/acs/123"> | ||
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" AllowCreate="true"/> | ||
</samlp:AuthnRequest> | ||
""" | ||
|
||
{:error, | ||
%DataSchema.Errors{ | ||
errors: [issuer: "Field was required but value supplied is considered empty"] | ||
}} = SAML.decode_saml_request(saml_request_mock) | ||
end | ||
end | ||
|
||
describe "with valid saml request" do | ||
context "returns parsed request struct" do | ||
saml_request_mock = """ | ||
<?xml version="1.0"?> | ||
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_123" Version="2.0" IssueInstant="2023-09-27T17:20:42.746Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Destination="https://accounts.google.com/o/saml2/idp?idpid=C03gu405z" AssertionConsumerServiceURL="https://auth.example.com/sso/saml/acs/123"> | ||
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"> | ||
https://example.com/123 | ||
</saml:Issuer> | ||
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" AllowCreate="true"/> | ||
</samlp:AuthnRequest> | ||
""" | ||
|
||
{:ok, | ||
%Request{ | ||
id: "_123", | ||
version: "2.0", | ||
issue_instant: "2023-09-27T17:20:42.746Z", | ||
issuer: "https://example.com/123", | ||
assertion_consumer_service_url: "https://auth.example.com/sso/saml/acs/123" | ||
}} = SAML.decode_saml_request(saml_request_mock) | ||
end | ||
end | ||
end |