This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
forked from okta/okta-aspnet
-
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.
Add additional configuration validations (okta#10)
* Add additional validations to make it easier for the developer to understand why Okta isn't working if they provided a bad config. * Refactor * Add FluentAssertions dependency to improve test clarity * Convert OktaOptionsValidator to an abstract class with an abstract ValidateOptions method that should be implemented by the derived classes. * Change String.Contains by IndexOf
- Loading branch information
1 parent
525f291
commit 59e8f46
Showing
10 changed files
with
202 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<appSettings> | ||
<add key="FluentAssertions.TestFramework" value="xunit"/> | ||
</appSettings> | ||
</configuration> |
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Okta.AspNet.Abstractions.Test | ||
{ | ||
public class MockOktaOptionsValidator : OktaOptionsValidator | ||
{ | ||
protected override void ValidateOptions(OktaOptions options) | ||
{ | ||
return; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Okta.AspNet.Abstractions.Test | ||
{ | ||
public static class OktaOptionsValidatorHelper | ||
{ | ||
public static readonly string VALID_ORG_URL = "https://myOktaDomain.oktapreview.com"; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
Okta.AspNet.Abstractions.Test/OktaOptionsValidatorShould.cs
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,97 @@ | ||
using System; | ||
using Xunit; | ||
using FluentAssertions; | ||
namespace Okta.AspNet.Abstractions.Test | ||
{ | ||
public class OktaOptionsValidatorShould | ||
{ | ||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public void FailWhenClientIdIsNullOrEmpty(String clientId) | ||
{ | ||
var options = new OktaOptions() | ||
{ | ||
OrgUrl = OktaOptionsValidatorHelper.VALID_ORG_URL, | ||
ClientId = clientId, | ||
}; | ||
|
||
Action action = () => new MockOktaOptionsValidator().Validate(options); | ||
action.Should().Throw<ArgumentNullException>().Where(e => e.ParamName == nameof(OktaOptions.ClientId)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public void FailIfOrgUrlIsNullOrEmpty(String orgUrl) | ||
{ | ||
var options = new OktaOptions() | ||
{ | ||
OrgUrl = orgUrl, | ||
ClientId = "ClientId" | ||
}; | ||
|
||
Action action = () => new MockOktaOptionsValidator().Validate(options); | ||
action.Should().Throw<ArgumentNullException>().Where(e => e.ParamName == nameof(OktaOptions.OrgUrl)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("http://myOktaDomain.oktapreview.com")] | ||
[InlineData("httsp://myOktaDomain.oktapreview.com")] | ||
[InlineData("invalidOrgUrl")] | ||
public void FailIfOrgUrlIsNotStartingWithHttps(String orgUrl) | ||
{ | ||
var options = new OktaMvcOptions() | ||
{ | ||
OrgUrl = orgUrl, | ||
ClientId = "ClientId" | ||
}; | ||
|
||
Action action = () => new MockOktaOptionsValidator().Validate(options); | ||
action.Should().Throw<ArgumentException>().Where(e => e.ParamName == nameof(OktaOptions.OrgUrl)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://{Youroktadomain}.com")] | ||
[InlineData("https://{yourOktaDomain}.com")] | ||
[InlineData("https://{YourOktaDomain}.com")] | ||
public void FailIfOrgUrlIsNotDefined(String orgUrl) | ||
{ | ||
var options = new OktaMvcOptions() | ||
{ | ||
OrgUrl = orgUrl, | ||
ClientId = "ClientId" | ||
}; | ||
|
||
Action action = () => new MockOktaOptionsValidator().Validate(options); | ||
action.Should().Throw<ArgumentException>().Where(e => e.ParamName == nameof(OktaOptions.OrgUrl)); | ||
} | ||
|
||
[Fact] | ||
public void FailIfOrgUrlIsIncludingAdmin() | ||
{ | ||
var options = new OktaMvcOptions() | ||
{ | ||
OrgUrl = "https://myOktaOrg-admin.oktapreview.com", | ||
ClientId = "ClientId" | ||
}; | ||
|
||
Action action = () => new MockOktaOptionsValidator().Validate(options); | ||
action.Should().Throw<ArgumentException>().Where(e => e.ParamName == nameof(OktaOptions.OrgUrl)); | ||
} | ||
|
||
[Fact] | ||
public void FailIfOrgUrlHasTypo() | ||
{ | ||
var options = new OktaMvcOptions() | ||
{ | ||
OrgUrl = "https://myOktaDomain.oktapreview.com.com", | ||
ClientId = "ClientId" | ||
}; | ||
|
||
Action action = () => new MockOktaOptionsValidator().Validate(options); | ||
action.Should().Throw<ArgumentException>().Where(e => e.ParamName == nameof(OktaOptions.OrgUrl)); | ||
} | ||
} | ||
} | ||
|
67 changes: 0 additions & 67 deletions
67
Okta.AspNet.Abstractions.Test/OktaWebApiOptionsValidatorShould.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.