Skip to content

Commit

Permalink
Merge pull request #118 from zhenlineo/1.1-remove-tofu
Browse files Browse the repository at this point in the history
Removing TOFU and TrustNonLocal
  • Loading branch information
Zhen Li authored Nov 21, 2016
2 parents 50e5968 + 20545d3 commit 4b8f06f
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 381 deletions.
12 changes: 7 additions & 5 deletions Neo4j.Driver/Neo4j.Driver.IntegrationTests/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void TlsSigned()
{
//tag::tls-signed[]
var driver = GraphDatabase.Driver("bolt://localhost", AuthTokens.Basic("neo4j", "neo4j"),
Config.Builder.WithEncryptionLevel(EncryptionLevel.Encrypted).WithTrustStrategy(TrustStrategy.TrustSystemCaSignedCertificates()).ToConfig());
Config.Builder.WithEncryptionLevel(EncryptionLevel.Encrypted).WithTrustStrategy(TrustStrategy.TrustSystemCaSignedCertificates).ToConfig());
//end::tls-signed[]
driver.Dispose();
}
Expand All @@ -335,16 +335,18 @@ private void ClearDatabase()
driver.Dispose();
}

//tag::tls-trust-on-first-use[]
// Not supported in this driver
//end::tls-trust-on-first-use[]

[Fact]
public void TlsTrustOnFirstUse()
{
var knownHostsFileName = Path.GetTempPath() + Guid.NewGuid() + ".tmp";
//tag::tls-trust-on-first-use[]

var driver = GraphDatabase.Driver("bolt://localhost", AuthTokens.Basic("neo4j", "neo4j"),
Config.Builder.WithEncryptionLevel(EncryptionLevel.Encrypted).WithTrustStrategy(TrustStrategy.TrustOnFirstUse(knownHostsFileName))
Config.Builder.WithEncryptionLevel(EncryptionLevel.Encrypted).WithTrustStrategy(TrustStrategy.TrustAllCertificates)
.ToConfig());
//end::tls-trust-on-first-use[]

using (var session = driver.Session())
{
var result = session.Run("RETURN 1 as n");
Expand Down
37 changes: 15 additions & 22 deletions Neo4j.Driver/Neo4j.Driver.Tests/ConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public class DefaultConfigTests
public void DefaultConfigShouldGiveCorrectValueBack()
{
var config = Config.DefaultConfig;
config.EncryptionLevel.Should().Be(EncryptionLevel.EncryptedNonLocal);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustOnFirstUse);
config.TrustStrategy.FileName().Should().BeNull();
config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.Should().Be(TrustStrategy.TrustAllCertificates);
config.Logger.Should().BeOfType<DebugLogger>();
config.MaxIdleSessionPoolSize.Should().Be(10);
}
Expand All @@ -46,8 +45,7 @@ public void ShouldUseDefaultValueIfNotSpecified()
var config = new Config {EncryptionLevel = EncryptionLevel.Encrypted};

config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustOnFirstUse);
config.TrustStrategy.FileName().Should().BeNull();
config.TrustStrategy.Should().Be(TrustStrategy.TrustAllCertificates);
config.Logger.Should().BeOfType<DebugLogger>();
config.MaxIdleSessionPoolSize.Should().Be(10);
}
Expand All @@ -56,9 +54,8 @@ public void ShouldUseDefaultValueIfNotSpecified()
public void WithLoggingShouldModifyTheSingleValue()
{
var config = Config.Builder.WithLogger(null).ToConfig();
config.EncryptionLevel.Should().Be(EncryptionLevel.EncryptedNonLocal);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustOnFirstUse);
config.TrustStrategy.FileName().Should().BeNull();
config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.Should().Be(TrustStrategy.TrustAllCertificates);
config.Logger.Should().BeNull();
config.MaxIdleSessionPoolSize.Should().Be(10);
}
Expand All @@ -67,31 +64,28 @@ public void WithLoggingShouldModifyTheSingleValue()
public void WithPoolSizeShouldModifyTheSingleValue()
{
var config = Config.Builder.WithMaxIdleSessionPoolSize(3).ToConfig();
config.EncryptionLevel.Should().Be(EncryptionLevel.EncryptedNonLocal);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustOnFirstUse);
config.TrustStrategy.FileName().Should().BeNull();
config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.Should().Be(TrustStrategy.TrustAllCertificates);
config.Logger.Should().BeOfType<DebugLogger>();
config.MaxIdleSessionPoolSize.Should().Be(3);
}

[Fact]
public void WithEncryptionLevelShouldModifyTheSingleValue()
{
var config = Config.Builder.WithEncryptionLevel(EncryptionLevel.Encrypted).ToConfig();
config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustOnFirstUse);
config.TrustStrategy.FileName().Should().BeNull();
var config = Config.Builder.WithEncryptionLevel(EncryptionLevel.None).ToConfig();
config.EncryptionLevel.Should().Be(EncryptionLevel.None);
config.TrustStrategy.Should().Be(TrustStrategy.TrustAllCertificates);
config.Logger.Should().BeOfType<DebugLogger>();
config.MaxIdleSessionPoolSize.Should().Be(10);
}

[Fact]
public void WithTrustStrategyShouldModifyTheSingleValue()
{
var config = Config.Builder.WithTrustStrategy(TrustStrategy.TrustSystemCaSignedCertificates()).ToConfig();
config.EncryptionLevel.Should().Be(EncryptionLevel.EncryptedNonLocal);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustSystemCaSignedCertificates);
config.TrustStrategy.FileName().Should().BeNull();
var config = Config.Builder.WithTrustStrategy(TrustStrategy.TrustSystemCaSignedCertificates).ToConfig();
config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.Should().Be(TrustStrategy.TrustSystemCaSignedCertificates);
config.Logger.Should().BeOfType<DebugLogger>();
config.MaxIdleSessionPoolSize.Should().Be(10);
}
Expand All @@ -110,9 +104,8 @@ public void ChangingNewConfigShouldNotAffectOtherConfig()
config1.MaxIdleSessionPoolSize.Should().Be(3);
config1.Logger.Should().BeOfType<DebugLogger>();

config.EncryptionLevel.Should().Be(EncryptionLevel.EncryptedNonLocal);
config.TrustStrategy.ServerTrustStrategy().Should().Be(TrustStrategy.Strategy.TrustOnFirstUse);
config.TrustStrategy.FileName().Should().BeNull();
config.EncryptionLevel.Should().Be(EncryptionLevel.Encrypted);
config.TrustStrategy.Should().Be(TrustStrategy.TrustAllCertificates);
config.Logger.Should().BeOfType<DebugLogger>();
config.MaxIdleSessionPoolSize.Should().Be(10);
}
Expand Down
175 changes: 0 additions & 175 deletions Neo4j.Driver/Neo4j.Driver.Tests/Connector/TrustOnFirstUseTests.cs

This file was deleted.

1 change: 0 additions & 1 deletion Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
<Compile Include="Connector\ChunkedOutputTest.cs" />
<Compile Include="Connector\MessageResponseHandlerTests.cs" />
<Compile Include="Connector\SocketExtensionTests.cs" />
<Compile Include="Connector\TrustOnFirstUseTests.cs" />
<Compile Include="DebugLoggerTests.cs" />
<Compile Include="DriverTests.cs" />
<Compile Include="EntityTests.cs" />
Expand Down
Loading

0 comments on commit 4b8f06f

Please sign in to comment.