public void version_is_required_according_to_the_specification() { var authService = Substitute.For<IAuthenticationService>(); var frame = new BasicFrame("STOMP"); var client = Substitute.For<IStompClient>(); var sut = new ConnectHandler(authService, "Kickass"); var actual = sut.Process(client, frame); actual.Should().NotBeNull(); actual.Headers["version"].Should().Be("2.0"); actual.Headers["message"].Should().Be("Missing the 'accept-version' header."); }
public void only_accepting_20_clients() { var authService = Substitute.For<IAuthenticationService>(); var frame = new BasicFrame("STOMP"); var client = Substitute.For<IStompClient>(); frame.Headers["accept-version"] = "1.1"; var sut = new ConnectHandler(authService, "Kickass"); var actual = sut.Process(client, frame); actual.Should().NotBeNull(); actual.Headers["version"].Should().Be("2.0"); actual.Headers["message"].Should().Be("Only accepting stomp 2.0 clients."); }
public void always_accept_when_authentication_is_turned_off() { var authService = Substitute.For<IAuthenticationService>(); var frame = new BasicFrame("STOMP"); var client = Substitute.For<IStompClient>(); frame.Headers["accept-version"] = "2.0"; client.SessionKey.Returns(Guid.NewGuid().ToString()); var sut = new ConnectHandler(authService, "Kickass"); var actual = sut.Process(client, frame); actual.Should().NotBeNull(); actual.Headers["version"].Should().Be("2.0"); actual.Headers["server"].Should().Be("Kickass"); actual.Headers["session"].Should().NotBeNullOrEmpty(); client.ReceivedWithAnyArgs().SetAsAuthenticated(null); }
/// <summary> /// Initializes a new instance of the <see cref="StompBroker" /> class. /// </summary> /// <param name="repository"> /// Used to provide all queues that this broker is for. There is a built in class, /// <see cref="MemoryQueueRepository" />, which you can use. /// </param> /// <exception cref="System.ArgumentNullException">repository</exception> public StompBroker(IQueueRepository repository) { if (repository == null) throw new ArgumentNullException("repository"); _queues = repository; _tcpListener = new StompTcpListener {MessageReceived = OnMessageReceived, MessageSent = OnMessageDelivered}; _tcpListener.ClientConnected += OnClientConnected; _tcpListener.ClientDisconnected += OnClientDisconnected; ServerName = "Griffin.Queue/1.0"; var connectHandler = new ConnectHandler(new NoAuthenticationService(), ServerName); _frameHandlers.Add("ACK", new AckHandler()); _frameHandlers.Add("ABORT", new AbortHandler()); _frameHandlers.Add("BEGIN", new BeginHandler()); _frameHandlers.Add("COMMIT", new CommitHandler()); _frameHandlers.Add("CONNECT", connectHandler); _frameHandlers.Add("DISCONNECT", new DisconnectHandler()); _frameHandlers.Add("NACK", new NackHandler(_queues)); _frameHandlers.Add("SEND", new SendHandler(_queues)); _frameHandlers.Add("SUBSCRIBE", new SubscribeHandler(_queues)); _frameHandlers.Add("STOMP", connectHandler); }
public void using_authentication_but_no_password_was_supplied() { var authService = Substitute.For<IAuthenticationService>(); authService.IsActivated.Returns(true); var frame = new BasicFrame("STOMP"); var client = Substitute.For<IStompClient>(); frame.Headers["accept-version"] = "2.0"; frame.Headers["login"] = "******"; client.SessionKey.Returns(Guid.NewGuid().ToString()); var sut = new ConnectHandler(authService, "Kickass"); var actual = sut.Process(client, frame); actual.Headers["message"].Should().NotBeNullOrEmpty(); }
public void using_authentication_but_with_incorrect_password() { var authService = Substitute.For<IAuthenticationService>(); authService.IsActivated.Returns(true); authService.Login("hello", "world").Returns(new LoginResponse() { IsSuccessful = false, Token = "mamma", Reason = "Incorrect password"}); var frame = new BasicFrame("STOMP"); var client = Substitute.For<IStompClient>(); frame.Headers["accept-version"] = "2.0"; frame.Headers["login"] = "******"; frame.Headers["passcode"] = "world"; client.SessionKey.Returns(Guid.NewGuid().ToString()); var sut = new ConnectHandler(authService, "Kickass"); var actual = sut.Process(client, frame); actual.Headers["message"].Should().Be("Incorrect password"); }
public void using_authentication() { var authService = Substitute.For<IAuthenticationService>(); authService.IsActivated.Returns(true); authService.Login("hello", "world").Returns(new LoginResponse() {IsSuccessful = true, Token = "mamma"}); var frame = new BasicFrame("STOMP"); var client = Substitute.For<IStompClient>(); frame.Headers["accept-version"] = "2.0"; frame.Headers["login"] = "******"; frame.Headers["passcode"] = "world"; client.SessionKey.Returns(Guid.NewGuid().ToString()); var sut = new ConnectHandler(authService, "Kickass"); var actual = sut.Process(client, frame); actual.Should().NotBeNull(); actual.Headers["version"].Should().Be("2.0"); actual.Headers["server"].Should().Be("Kickass"); actual.Headers["session"].Should().NotBeNull(); client.ReceivedWithAnyArgs().SetAsAuthenticated("mamma"); }