Exemplo n.º 1
0
        public void Invalid_Wrong_Interaction()
        {
            var requestMock = new Mock <HttpRequest>();

            requestMock.Setup(x => x.Method).Returns("POST");
            requestMock.Setup(x => x.Path).Returns("/DocumentReference");
            requestMock.Setup(x => x.Headers).Returns(new HeaderDictionary()
            {
                { HeaderNames.Authorization, "we-are-not-validating-jwt-here" },
                { FhirConstants.HeaderFromAsid, "000" },
                { FhirConstants.HeaderToAsid, "999" }
            });


            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.Request).Returns(requestMock.Object);


            var sspAuthorizationMiddleware = new SpineAuthorizationMiddleware(next: (innerHttpContext) => Task.FromResult(0), spineSettings: _spineSettings, sdsService: _sdsService, nrlsValidation: _nrlsValidation);

            //Test will fail if invalid
            Assert.ThrowsAsync <HttpFhirException>(async delegate
            {
                await sspAuthorizationMiddleware.Invoke(contextMock.Object, _nrlsSettings);
            });
        }
Exemplo n.º 2
0
        public void Invalid_Header_Authorization_Missing()
        {
            var requestMock = new Mock <HttpRequest>();

            requestMock.Setup(x => x.Method).Returns("GET");
            requestMock.Setup(x => x.Path).Returns("/DocumentReference");
            requestMock.Setup(x => x.Headers).Returns(new HeaderDictionary() //Removed Authorization Header
            {
                { FhirConstants.HeaderFromAsid, "000" },
                { FhirConstants.HeaderToAsid, "999" }
            });

            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.Request).Returns(requestMock.Object);

            var sspAuthorizationMiddleware = new SpineAuthorizationMiddleware(next: (innerHttpContext) => Task.FromResult(0), spineSettings: _spineSettings, sdsService: _sdsService, nrlsValidation: _nrlsValidation);

            Assert.ThrowsAsync <HttpFhirException>(async delegate
            {
                await sspAuthorizationMiddleware.Invoke(contextMock.Object, _nrlsSettings);
            });
        }
Exemplo n.º 3
0
        public async void Valid_Update_Interaction()
        {
            var requestMock = new Mock <HttpRequest>();

            requestMock.Setup(x => x.Method).Returns("PATCH");
            requestMock.Setup(x => x.Path).Returns("/DocumentReference");
            requestMock.Setup(x => x.Headers).Returns(new HeaderDictionary()
            {
                { HeaderNames.Authorization, "we-are-not-validating-jwt-here-for-patch" },
                { FhirConstants.HeaderFromAsid, "20000000018" },
                { FhirConstants.HeaderToAsid, "999" }
            });


            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.Request).Returns(requestMock.Object);


            var sspAuthorizationMiddleware = new SpineAuthorizationMiddleware(next: (innerHttpContext) => Task.FromResult(0), spineSettings: _spineSettings, sdsService: _sdsService, nrlsValidation: _nrlsValidation);

            //Test will fail if invalid
            await sspAuthorizationMiddleware.Invoke(contextMock.Object, _nrlsSettings);
        }