コード例 #1
0
        public void WhenConstructedSetsTheValueProperty()
        {
            var header = new BasicAuthorizationHeader("username", "password");

            string expected = Convert.ToBase64String(Encoding.UTF8.GetBytes($"username:password"));

            header.Value.Should().Be($"Basic {expected}");
        }
コード例 #2
0
            public void Must_parse_correctly(string headerValue, string expectedUserid, string expectedPassword)
            {
                BasicAuthorizationHeader header = BasicAuthorizationHeader.Parse(headerValue);

                Assert.That(header, Is.Not.Null);
                Assert.That(header.AuthScheme, Is.StringMatching("[Bb]asic"));
                Assert.That(header.Userid, Is.EqualTo(expectedUserid));
                Assert.That(header.Password, Is.EqualTo(expectedPassword));
            }
コード例 #3
0
 private static BasicAuthorizationHeader ReadBasicAuthHeader(ICommunicationContext context)
 {
     try
     {
         var header = context.Request.Headers["Authorization"];
         return(string.IsNullOrEmpty(header) ? null : BasicAuthorizationHeader.Parse(header));
     } catch (ArgumentException ex)
     {
         return(null);
     }
 }
コード例 #4
0
        public void WhenConstructedSetsTheNamePropertyToAuthorization()
        {
            var header = new BasicAuthorizationHeader("username", "password");

            header.Name.Should().Be("Authorization");
        }
コード例 #5
0
 public void Must_not_result_in_header(string headerValue)
 {
     Assert.That(BasicAuthorizationHeader.Parse(headerValue), Is.Null);
 }