Skip to content

Commit

Permalink
Add header overwrite test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattosaurus committed Jan 26, 2024
1 parent 26d08f0 commit 692f0e0
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 0 deletions.
34 changes: 34 additions & 0 deletions PgpCore.Tests/UnitTests/Encrypt/EncryptAsync.File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,40 @@ public async Task EncryptAsync_EncryptMessageWithHeaders_ShouldEncryptMessage(Ke
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public async Task EncryptAsync_EncryptMessageAndOverwriteVersionHeader_ShouldEncryptMessage(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
await testFactory.ArrangeAsync(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKeyFileInfo, testFactory.PrivateKeyFileInfo, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys);

// Act
await pgpEncrypt.EncryptAsync(testFactory.ContentFileInfo, testFactory.EncryptedContentFileInfo, headers: new Dictionary<string, string> { { "Version", TESTHEADERVALUE } });

// Assert
using (new AssertionScope())
{
testFactory.EncryptedContentFileInfo.Exists.Should().BeTrue();
PgpInspectResult pgpInspectResult = await pgpEncrypt.InspectAsync(testFactory.EncryptedContentFileInfo);
pgpInspectResult.IsEncrypted.Should().BeTrue();
pgpInspectResult.IsSigned.Should().BeFalse();
pgpInspectResult.IsArmored.Should().BeTrue();
pgpInspectResult.IsIntegrityProtected.Should().BeTrue();
pgpInspectResult.FileName.Should().Be(testFactory.ContentFileInfo.Name);
pgpInspectResult.MessageHeaders.Should().HaveCount(1);
pgpInspectResult.MessageHeaders.Single().Key.Should().Be("Version");
pgpInspectResult.MessageHeaders.Single().Value.Should().Be(TESTHEADERVALUE);
}

// Teardown
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
Expand Down
35 changes: 35 additions & 0 deletions PgpCore.Tests/UnitTests/Encrypt/EncryptAsync.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,41 @@ public async Task EncryptAsync_EncryptMessageWithHeaders_ShouldEncryptMessage(Ke
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public async Task EncryptAsync_EncryptMessageAndOverwriteVersionHeader_ShouldEncryptMessage(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
await testFactory.ArrangeAsync(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKeyStream, testFactory.PrivateKeyStream, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys);

// Act
using (Stream outputFileStream = testFactory.EncryptedContentFileInfo.Create())
await pgpEncrypt.EncryptAsync(testFactory.ContentStream, outputFileStream, headers: new Dictionary<string, string> { { "Version", TESTHEADERVALUE } });

// Assert
using (new AssertionScope())
{
testFactory.EncryptedContentFileInfo.Exists.Should().BeTrue();
PgpInspectResult pgpInspectResult = await pgpEncrypt.InspectAsync(testFactory.EncryptedContentFileInfo);
pgpInspectResult.IsEncrypted.Should().BeTrue();
pgpInspectResult.IsSigned.Should().BeFalse();
pgpInspectResult.IsArmored.Should().BeTrue();
pgpInspectResult.IsIntegrityProtected.Should().BeTrue();
pgpInspectResult.FileName.Should().Be(DEFAULTNAME);
pgpInspectResult.MessageHeaders.Should().HaveCount(1);
pgpInspectResult.MessageHeaders.Single().Key.Should().Be("Version");
pgpInspectResult.MessageHeaders.Single().Value.Should().Be(TESTHEADERVALUE);
}

// Teardown
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
Expand Down
34 changes: 34 additions & 0 deletions PgpCore.Tests/UnitTests/Encrypt/EncryptAsync.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,40 @@ public async Task EncryptAsync_EncryptMessageWithHeaders_ShouldEncryptMessage(Ke
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public async Task EncryptAsync_EncryptMessageAndOverwriteVersionHeader_ShouldEncryptMessage(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
await testFactory.ArrangeAsync(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKey, testFactory.PrivateKey, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys);

// Act
string encryptedContent = await pgpEncrypt.EncryptAsync(testFactory.Content, headers: new Dictionary<string, string> { { "Version", TESTHEADERVALUE } });

// Assert
using (new AssertionScope())
{
encryptedContent.Should().NotBeNullOrEmpty();
PgpInspectResult pgpInspectResult = await pgpEncrypt.InspectAsync(encryptedContent);
pgpInspectResult.IsEncrypted.Should().BeTrue();
pgpInspectResult.IsSigned.Should().BeFalse();
pgpInspectResult.IsArmored.Should().BeTrue();
pgpInspectResult.IsIntegrityProtected.Should().BeTrue();
pgpInspectResult.FileName.Should().Be(DEFAULTNAME);
pgpInspectResult.MessageHeaders.Should().HaveCount(1);
pgpInspectResult.MessageHeaders.Single().Key.Should().Be("Version");
pgpInspectResult.MessageHeaders.Single().Value.Should().Be(TESTHEADERVALUE);
}

// Teardown
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
Expand Down
34 changes: 34 additions & 0 deletions PgpCore.Tests/UnitTests/Encrypt/EncryptSync.File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,40 @@ public void Encrypt_EncryptMessageWithHeaders_ShouldEncryptMessage(KeyType keyTy
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public void Encrypt_EncryptMessageAndOverwriteVersionHeader_ShouldEncryptMessage(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
testFactory.Arrange(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKeyFileInfo, testFactory.PrivateKeyFileInfo, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys);

// Act
pgpEncrypt.Encrypt(testFactory.ContentFileInfo, testFactory.EncryptedContentFileInfo, headers: new Dictionary<string, string> { { "Version", TESTHEADERVALUE } });

// Assert
using (new AssertionScope())
{
testFactory.EncryptedContentFileInfo.Exists.Should().BeTrue();
PgpInspectResult pgpInspectResult = pgpEncrypt.Inspect(testFactory.EncryptedContentFileInfo);
pgpInspectResult.IsEncrypted.Should().BeTrue();
pgpInspectResult.IsSigned.Should().BeFalse();
pgpInspectResult.IsArmored.Should().BeTrue();
pgpInspectResult.IsIntegrityProtected.Should().BeTrue();
pgpInspectResult.FileName.Should().Be(testFactory.ContentFileInfo.Name);
pgpInspectResult.MessageHeaders.Should().HaveCount(1);
pgpInspectResult.MessageHeaders.Single().Key.Should().Be("Version");
pgpInspectResult.MessageHeaders.Single().Value.Should().Be(TESTHEADERVALUE);
}

// Teardown
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
Expand Down
35 changes: 35 additions & 0 deletions PgpCore.Tests/UnitTests/Encrypt/EncryptSync.Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,41 @@ public void Encrypt_EncryptMessageWithHeaders_ShouldEncryptMessage(KeyType keyTy
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public void Encrypt_EncryptMessageAndOverwriteVersionHeader_ShouldEncryptMessage(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
testFactory.Arrange(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKeyStream, testFactory.PrivateKeyStream, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys);

// Act
using (Stream outputFileStream = testFactory.EncryptedContentFileInfo.Create())
pgpEncrypt.Encrypt(testFactory.ContentStream, outputFileStream, headers: new Dictionary<string, string> { { "Version", TESTHEADERVALUE } });

// Assert
using (new AssertionScope())
{
testFactory.EncryptedContentFileInfo.Exists.Should().BeTrue();
PgpInspectResult pgpInspectResult = pgpEncrypt.Inspect(testFactory.EncryptedContentFileInfo);
pgpInspectResult.IsEncrypted.Should().BeTrue();
pgpInspectResult.IsSigned.Should().BeFalse();
pgpInspectResult.IsArmored.Should().BeTrue();
pgpInspectResult.IsIntegrityProtected.Should().BeTrue();
pgpInspectResult.FileName.Should().Be(DEFAULTNAME);
pgpInspectResult.MessageHeaders.Should().HaveCount(1);
pgpInspectResult.MessageHeaders.Single().Key.Should().Be("Version");
pgpInspectResult.MessageHeaders.Single().Value.Should().Be(TESTHEADERVALUE);
}

// Teardown
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
Expand Down
34 changes: 34 additions & 0 deletions PgpCore.Tests/UnitTests/Encrypt/EncryptSync.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,40 @@ public void Encrypt_EncryptMessageWithHeaders_ShouldEncryptMessage(KeyType keyTy
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
[InlineData(KeyType.KnownGpg)]
public void Encrypt_EncryptMessageAndOverwriteVersionHeader_ShouldEncryptMessage(KeyType keyType)
{
// Arrange
TestFactory testFactory = new TestFactory();
testFactory.Arrange(keyType, FileType.Known);
EncryptionKeys encryptionKeys = new EncryptionKeys(testFactory.PublicKey, testFactory.PrivateKey, testFactory.Password);
PGP pgpEncrypt = new PGP(encryptionKeys);

// Act
string encryptedContent = pgpEncrypt.Encrypt(testFactory.Content, headers: new Dictionary<string, string> { { "Version", TESTHEADERVALUE } });

// Assert
using (new AssertionScope())
{
encryptedContent.Should().NotBeNullOrEmpty();
PgpInspectResult pgpInspectResult = pgpEncrypt.Inspect(encryptedContent);
pgpInspectResult.IsEncrypted.Should().BeTrue();
pgpInspectResult.IsSigned.Should().BeFalse();
pgpInspectResult.IsArmored.Should().BeTrue();
pgpInspectResult.IsIntegrityProtected.Should().BeTrue();
pgpInspectResult.FileName.Should().Be(DEFAULTNAME);
pgpInspectResult.MessageHeaders.Should().HaveCount(1);
pgpInspectResult.MessageHeaders.Single().Key.Should().Be("Version");
pgpInspectResult.MessageHeaders.Single().Value.Should().Be(TESTHEADERVALUE);
}

// Teardown
testFactory.Teardown();
}

[Theory]
[InlineData(KeyType.Generated)]
[InlineData(KeyType.Known)]
Expand Down

0 comments on commit 692f0e0

Please sign in to comment.