Skip to content

Commit

Permalink
Merge pull request Sustainsys#212 from explunit/authservicesurls-cons…
Browse files Browse the repository at this point in the history
…tructor

Implement constructor for supplying full Urls to AuthServicesUrls
  • Loading branch information
AndersAbel committed Mar 24, 2015
2 parents 39ce8ea + 55fd99c commit 9549b64
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Lisa Bylund
Sebastian Allard
Jozef Raschmann
Tor-Bj�rn Holmstr�m
Stephen Patches
32 changes: 31 additions & 1 deletion Kentor.AuthServices.Tests/WebSSO/AuthServicesUrlsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void AuthServicesUrls_Ctor_NullCheckApplicationUrl()
[TestMethod]
public void AuthServicesUrls_Ctor_NullCheckModulePath()
{
Action a = () => new AuthServicesUrls(new Uri("http://localhost"), null);
Action a = () => new AuthServicesUrls(new Uri("http://localhost"), modulePath: null);

a.ShouldThrow<ArgumentNullException>("modulePath");
}
Expand Down Expand Up @@ -77,5 +77,35 @@ public void AuthServicesUrls_Ctor_ChecksModulePathStartsWithSlash()

a.ShouldThrow<ArgumentException>("modulePath should start with /.");
}

[TestMethod]
public void AuthServiecsUrls_Ctor_AcceptsFullUrls()
{
var acsUrl = new Uri( "http://localhost:73/MyApp/MyAcs" );
var signinUrl = new Uri( "http://localhost:73/MyApp/MySignin" );

var subject = new AuthServicesUrls( acsUrl, signinUrl );

subject.AssertionConsumerServiceUrl.ToString().Should().Be(acsUrl.ToString());
subject.SignInUrl.ToString().Should().Be(signinUrl.ToString());
}

[TestMethod]
public void AuthServicesUrls_Ctor_AllowsNullAcs()
{
// AssertionConsumerServiceURL is optional in the SAML spec
var subject = new AuthServicesUrls(null, new Uri("http://localhost/signin"));

subject.AssertionConsumerServiceUrl.Should().Be(null);
subject.SignInUrl.ToString().Should().Be("http://localhost/signin");
}

[TestMethod]
public void AuthServicesUrls_Ctor_NullCheckSignin()
{
Action a = () => new AuthServicesUrls(new Uri("http://localhost/signin"), signInUrl: null);

a.ShouldThrow<ArgumentNullException>("signInUrl");
}
}
}
19 changes: 19 additions & 0 deletions Kentor.AuthServices/WebSSO/AuthServicesUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public AuthServicesUrls(HttpRequestData request, ISPOptions spOptions)
/// </summary>
/// <param name="applicationUrl">The full Url to the root of the application.</param>
/// <param name="modulePath">Path of module, starting with / and ending without.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1057:StringUriOverloadsCallSystemUriOverloads"
, Justification = "Incorrect warning. modulePath isn't a string representation of a Uri" )]
public AuthServicesUrls(Uri applicationUrl, string modulePath)
{
if (applicationUrl == null)
Expand All @@ -54,6 +56,23 @@ public AuthServicesUrls(Uri applicationUrl, string modulePath)
Init(applicationUrl, modulePath);
}

/// <summary>
/// Creates the urls for AuthServices based on the given full urls
/// for assertion consumer service and sign-in
/// </summary>
/// <param name="assertionConsumerServiceUrl">The full Url for the Assertion Consumer Service.</param>
/// <param name="signInUrl">The full Url for sign-in.</param>
public AuthServicesUrls(Uri assertionConsumerServiceUrl, Uri signInUrl)
{
if (signInUrl == null)
{
throw new ArgumentNullException("signInUrl");
}

AssertionConsumerServiceUrl = assertionConsumerServiceUrl;
SignInUrl = signInUrl;
}

void Init(Uri applicationUrl, string modulePath)
{
if (!modulePath.StartsWith("/", StringComparison.OrdinalIgnoreCase))
Expand Down

0 comments on commit 9549b64

Please sign in to comment.