Beispiel #1
0
        public void MessageInspector_GetsAndAttachesOwnToken()
        {
            // arrange
            var options = new CloudFoundryOptions()
            {
                AccessTokenEndpoint = "/tokenUrl", AuthorizationUrl = "http://localhost", ClientId = "validId", ClientSecret = "validSecret"
            };
            var inspector  = new JwtHeaderMessageInspector(options, null, GetMockHttpClient());
            var properties = new MessageProperties {
                { HttpRequestMessageProperty.Name, new HttpRequestMessageProperty() }
            };
            var message = new Mock <Message>();

            message.Setup(p => p.Properties).Returns(() => properties);
            var mo = message.Object;

            // act
            inspector.BeforeSendRequest(ref mo, null);
            HttpRequestMessageProperty httpRequestMessage;

            mo.Properties.TryGetValue(HttpRequestMessageProperty.Name, out object httpRequestMessageObject);
            httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;

            // assert
            Assert.True(httpRequestMessage.Headers.AllKeys.Any());
            Assert.Equal("Bearer someClientCredentialsToken", httpRequestMessage.Headers["Authorization"]);
        }
Beispiel #2
0
        public void MessageInspector_AttachesUserToken()
        {
            // arrange
            var options = new CloudFoundryOptions()
            {
                AuthorizationUrl = "http://localhost", ForwardUserCredentials = true
            };
            var inspector  = new JwtHeaderMessageInspector(options, "someToken");
            var properties = new MessageProperties {
                { HttpRequestMessageProperty.Name, new HttpRequestMessageProperty() }
            };
            var message = new Mock <Message>();

            message.Setup(p => p.Properties).Returns(() => properties);
            var mo = message.Object;

            // act
            inspector.BeforeSendRequest(ref mo, null);
            HttpRequestMessageProperty httpRequestMessage;

            mo.Properties.TryGetValue(HttpRequestMessageProperty.Name, out object httpRequestMessageObject);
            httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;

            // assert
            Assert.True(httpRequestMessage.Headers.AllKeys.Any());
            Assert.Equal("Bearer someToken", httpRequestMessage.Headers["Authorization"]);
        }