-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite required due to the configuration section expired keys collec…
…tion requiring unique items. Acceptance test to test that a message without a key identifier is still processed properly. Expired keys can also have a KeyFormat attribute, validations now done on the configuration object before conversion.
- Loading branch information
1 parent
75240b0
commit aff34f5
Showing
14 changed files
with
608 additions
and
175 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
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
90 changes: 90 additions & 0 deletions
90
...viceBus.AcceptanceTests/Encryption/When_using_Rijndael_without_incoming_key_identifier.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,90 @@ | ||
namespace NServiceBus.AcceptanceTests.Encryption | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using EndpointTemplates; | ||
using AcceptanceTesting; | ||
using NServiceBus.MessageMutator; | ||
using NUnit.Framework; | ||
using ScenarioDescriptors; | ||
|
||
public class When_using_Rijndael_without_incoming_key_identifier : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_process_decrypted_message_without_key_identifier() | ||
{ | ||
Scenario.Define<Context>() | ||
.WithEndpoint<Sender>(b => b.Given((bus, context) => bus.Send(new MessageWithSecretData | ||
{ | ||
Secret = "betcha can't guess my secret", | ||
}))) | ||
.WithEndpoint<Receiver>() | ||
.Done(c => c.Done) | ||
.Repeat(r => r.For(Transports.Default)) | ||
.Should(c => Assert.AreEqual("betcha can't guess my secret", c.Secret)) | ||
.Run(); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool Done { get; set; } | ||
public string Secret { get; set; } | ||
} | ||
|
||
public class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>(builder => builder.RijndaelEncryptionService("will-be-removed-by-transport-mutator", Encoding.ASCII.GetBytes("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))) | ||
.AddMapping<MessageWithSecretData>(typeof(Receiver)); | ||
} | ||
} | ||
|
||
public class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
var keys = new Dictionary<string, byte[]> | ||
{ | ||
{"new", Encoding.ASCII.GetBytes("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") }, | ||
}; | ||
|
||
var expiredKeys = new[] { Encoding.ASCII.GetBytes("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") }; | ||
EndpointSetup<DefaultServer>(builder => builder.RijndaelEncryptionService("new", keys, expiredKeys)); | ||
|
||
} | ||
|
||
public class Handler : IHandleMessages<MessageWithSecretData> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(MessageWithSecretData message) | ||
{ | ||
Context.Secret = message.Secret.Value; | ||
Context.Done = true; | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class MessageWithSecretData : IMessage | ||
{ | ||
public WireEncryptedString Secret { get; set; } | ||
} | ||
|
||
|
||
class RemoveKeyIdentifierHeaderMutator : IMutateIncomingTransportMessages, INeedInitialization | ||
{ | ||
public void MutateIncoming(TransportMessage transportMessage) | ||
{ | ||
transportMessage.Headers.Remove(Headers.KeyIdentifier); | ||
} | ||
|
||
public void Customize(BusConfiguration configuration) | ||
{ | ||
configuration.RegisterComponents(c => c.ConfigureComponent<RemoveKeyIdentifierHeaderMutator>(DependencyLifecycle.InstancePerCall)); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.