Skip to content

Commit

Permalink
Merge branch 'release/2.0.0' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfowler committed Mar 15, 2017
2 parents 8f6c59b + 8a1f01b commit 7607060
Show file tree
Hide file tree
Showing 58 changed files with 3,180 additions and 883 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: csharp
solution: CSF.Security.sln

install:
- nuget restore CSF.Security.sln
- nuget install NUnit.ConsoleRunner -Version 3.6.1 -OutputDirectory testrunner

script:
- xbuild /p:Configuration=Debug CSF.Security.sln
- mono "./testrunner/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe" $(find ./CSF.Security.Tests/ -type f -path "*/bin/Debug/*" -name "CSF.Security.Tests.dll")
8 changes: 8 additions & 0 deletions CSF.Security.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><unitTestProvider name="NUnit" /></specFlow></configuration>
43 changes: 43 additions & 0 deletions CSF.Security.Tests/Authentication/Authentication.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Feature: Login with a username and password
This performs authentication against a stored set of
credentials using the PBKDF2 algorithm, in order to
determine whether or not a login may happen or not.

Scenario: Login fails when an invalid username is used
Given there is no user account in the database named 'joebloggs'
When I attempt to log in with the username 'joebloggs' and the password 'secret'
Then I should not be logged in

Scenario: Login fails with a valid username but invalid password
Given there is a user account in the database named 'joebloggs' with password 'secret'
When I attempt to log in with the username 'joebloggs' and the password 'wrong'
Then I should not be logged in

Scenario: Login succeeds with a valid username and password
Given there is a user account in the database named 'joebloggs' with password 'secret'
When I attempt to log in with the username 'joebloggs' and the password 'secret'
Then I should be logged in

Scenario: An external service listening for success is notified when login succeeds
Given there is a user account in the database named 'joebloggs' with password 'secret'
And there is an external service listening for success
When I attempt to log in with the username 'joebloggs' and the password 'secret'
Then the external service should be notified

Scenario: An external service listening for success is not notified when login fails
Given there is a user account in the database named 'joebloggs' with password 'secret'
And there is an external service listening for success
When I attempt to log in with the username 'joebloggs' and the password 'wrong'
Then the external service should not be notified

Scenario: An external service listening for failure is not notified when login succeeds
Given there is a user account in the database named 'joebloggs' with password 'secret'
And there is an external service listening for failure
When I attempt to log in with the username 'joebloggs' and the password 'secret'
Then the external service should not be notified

Scenario: An external service listening for failure is notified when login fails
Given there is a user account in the database named 'joebloggs' with password 'secret'
And there is an external service listening for failure
When I attempt to log in with the username 'joebloggs' and the password 'wrong'
Then the external service should be notified
195 changes: 195 additions & 0 deletions CSF.Security.Tests/Authentication/Authentication.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// TestJsonCredentialsSerializer.cs
//
// Author:
// Craig Fowler <craig@csf-dev.com>
//
// Copyright (c) 2017 Craig Fowler
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using CSF.Security;
using CSF.Security.Authentication;
using CSF.Security.Tests.Stubs;
using NUnit.Framework;

namespace CSF.Security.Tests.Authentication
{
[TestFixture]
public class JsonCredentialsSerializerTests
{
#region tests

[Test,AutoMoqData]
public void Serialize_creates_expected_json(StubCredentials credentials,
JsonCredentialsSerializer sut)
{
// Arrange
credentials.InitialisationNumber = 5;
credentials.Key = "My key";
credentials.Salt = "Salty goodness";

var expectedJson = "CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests:{\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";

// Act
var result = sut.Serialize(credentials);

// Assert
Assert.AreEqual(expectedJson, result);
}

[Test,AutoMoqData]
public void Deserialize_creates_expected_object(JsonCredentialsSerializer sut)
{
// Arrange
var json = "CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests:{\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";
var expectedCredentials = new StubCredentials {
InitialisationNumber = 5,
Key = "My key",
Salt = "Salty goodness",
};

// Act
var result = sut.Deserialize(json);

// Assert
Assert.IsInstanceOf<StubCredentials>(result, "Type");
var typedResult = (StubCredentials) result;
Assert.AreEqual(expectedCredentials.InitialisationNumber, typedResult.InitialisationNumber, "InitialisationNumber");
Assert.AreEqual(expectedCredentials.Key, typedResult.Key, "Key");
Assert.AreEqual(expectedCredentials.Salt, typedResult.Salt, "Salt");
}

#endregion
}
}
Loading

0 comments on commit 7607060

Please sign in to comment.