public void SetUp() { store = new UserStore(new LuceneDataProvider(new RAMDirectory(), Version.LUCENE_30)); mappings = new NameValueCollection(); middleware = new RoleMappingAuthenticationMiddleware(next) {Store = store, Settings = new NuGetWebApiSettings(NuGetWebApiSettings.DefaultAppSettingPrefix, new NameValueCollection(), mappings)}; domainAdminUser = new ApiUserPrincipal(new GenericIdentity("T-Rex"), new [] {"Domain Administrators"}); }
public async Task AuthenticateReturnsUser_DecoratesRequestUser() { const string upstreamRole = "Upstream Role"; var upstreamUser = new ApiUserPrincipal(new GenericIdentity("UpstreamUser"), new [] {upstreamRole}); requestMock.Object.User = upstreamUser; serviceMock.Setup(m => m.AuthenticateRequest(requestMock.Object)).Returns(user); await middleware.Invoke(contextMock.Object); Assert.That(requestMock.Object.User.Identity, Is.SameAs(upstreamUser.Identity), "Request.User.Identity"); Assert.That(requestMock.Object.User.IsInRole(upstreamRole), Is.True, "Request.User.IsInRole(upstreamRole)"); Assert.That(requestMock.Object.User.IsInRole(Role1), Is.True, "Request.User.IsInRole(Role1)"); }
public void SetUpContext() { nextMock = new Mock<OwinMiddleware>((OwinMiddleware)null); next = nextMock.Object; requestMock = new Mock<IOwinRequest>(); requestMock.SetupProperty(m => m.User); request = requestMock.Object; responseMock = new Mock<IOwinResponse>(); responseMock.SetupProperty(m => m.StatusCode); responseMock.SetupProperty(m => m.ReasonPhrase); response = responseMock.Object; contextMock = new Mock<IOwinContext>(); contextMock.SetupGet(m => m.Request).Returns(requestMock.Object); contextMock.SetupGet(m => m.Response).Returns(responseMock.Object); context = contextMock.Object; user = new ApiUserPrincipal(new GenericIdentity("T-Rex"), new[] { Role1 }); }