Esempio n. 1
0
        public async Task NoAuthorizeOnRequestReturnsChallenge(string expectedRealm)
        {
            var client   = TestBed.GetClient(o => o.Realm = expectedRealm);
            var response = await client.GetAsync("/");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
            Assert.Equal(string.Empty, await response.Content.ReadAsStringAsync());
            Assert.Equal($"Basic realm=\"{expectedRealm}\"", response.Headers.WwwAuthenticate.Single().ToString());
        }
Esempio n. 2
0
        public async Task DefaultTestBedRejectsCredentials()
        {
            var client = TestBed.GetClient();

            client.SetBasic("user", "pass");
            var response = await client.GetAsync("/");

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
            Assert.Equal(string.Empty, await response.Content.ReadAsStringAsync());
            Assert.Equal("Basic realm=\"\"", response.Headers.WwwAuthenticate.Single().ToString());
        }
Esempio n. 3
0
        public async Task ValidCredentialsAuthorize()
        {
            const string username = "******";
            const string password = "******";
            var          client   = TestBed.GetClient(builder => builder.AddBasicAuthentication(
                                                          userPass => Task.FromResult(userPass.username == username && userPass.password == password)));

            client.SetBasic(username, password);
            var response = await client.GetAsync("/");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(string.Empty, await response.Content.ReadAsStringAsync());
            Assert.False(response.Headers.WwwAuthenticate.Any());
        }