Skip to content

Commit

Permalink
Fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnavara committed Mar 19, 2024
1 parent b1ce3de commit a031ed4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public FakeNtlmServer(NetworkCredential expectedCredential)
public bool TargetIsServer { get; set; } = false;
public bool PreferUnicode { get; set; } = true;
public bool ForceNegotiateVersion { get; set; } = true;
public bool SupportsEncryption { get; set; } = true;

// Negotiation results
public bool IsAuthenticated { get; private set; }
Expand Down Expand Up @@ -233,10 +232,6 @@ private byte[] GenerateChallenge(Flags flags)
{
flags |= Flags.NegotiateVersion;
}
if (!SupportsEncryption)
{
flags &= ~Flags.NegotiateSeal;
}
// Remove any unsupported flags here
flags &= Flags.AllSupported;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,10 @@ public void NtlmIncorrectExchangeTest()
Assert.False(fakeNtlmServer.IsAuthenticated);
}

[ConditionalTheory(nameof(IsNtlmAvailable))]
[InlineData(true)]
[InlineData(false)]
public void NtlmEncryptionTest(bool serverSupportsEncryption)
[ConditionalFact(nameof(IsNtlmAvailable))]
public void NtlmEncryptionTest()
{
using FakeNtlmServer fakeNtlmServer = new FakeNtlmServer(s_testCredentialRight);
fakeNtlmServer.SupportsEncryption = serverSupportsEncryption;

NegotiateAuthentication ntAuth = new NegotiateAuthentication(
new NegotiateAuthenticationClientOptions
Expand All @@ -239,22 +236,15 @@ public void NtlmEncryptionTest(bool serverSupportsEncryption)
Assert.Equal(FakeNtlmServer.Flags.NegotiateSeal, (fakeNtlmServer.InitialClientFlags & FakeNtlmServer.Flags.NegotiateSeal));

byte[]? authenticateBlob = ntAuth.GetOutgoingBlob(challengeBlob, out statusCode);
Assert.Equal(NegotiateAuthenticationStatusCode.Completed, statusCode);
Assert.NotNull(authenticateBlob);

if (serverSupportsEncryption)
{
Assert.Equal(NegotiateAuthenticationStatusCode.Completed, statusCode);
Assert.NotNull(authenticateBlob);
// Validate that the NegotiateSeal flag survived the full exchange
Assert.Equal(FakeNtlmServer.Flags.NegotiateSeal, (fakeNtlmServer.NegotiatedFlags & FakeNtlmServer.Flags.NegotiateSeal));

byte[]? empty = fakeNtlmServer.GetOutgoingBlob(authenticateBlob);
Assert.Null(empty);
Assert.True(fakeNtlmServer.IsAuthenticated);
}
else
{
Assert.Equal(NegotiateAuthenticationStatusCode.QopNotSupported, statusCode);
}
byte[]? empty = fakeNtlmServer.GetOutgoingBlob(authenticateBlob);
Assert.Null(empty);
Assert.True(fakeNtlmServer.IsAuthenticated);

// Validate that the NegotiateSeal flag survived the full exchange
Assert.Equal(FakeNtlmServer.Flags.NegotiateSeal, (fakeNtlmServer.NegotiatedFlags & FakeNtlmServer.Flags.NegotiateSeal));
}

[ConditionalFact(nameof(IsNtlmAvailable))]
Expand Down

0 comments on commit a031ed4

Please sign in to comment.