Skip to content

Commit

Permalink
Implement constructor for supplying full Urls to AuthServicesUrls
Browse files Browse the repository at this point in the history
  • Loading branch information
explunit committed Mar 19, 2015
1 parent 39ce8ea commit 09d1b61
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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"), (string)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"), (Uri)null);

a.ShouldThrow<ArgumentNullException>("signInUrl");
}
}
}
18 changes: 18 additions & 0 deletions Kentor.AuthServices/WebSSO/AuthServicesUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ 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" )]
public AuthServicesUrls(Uri applicationUrl, string modulePath)
{
if (applicationUrl == null)
Expand All @@ -54,6 +55,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 09d1b61

Please sign in to comment.