コード例 #1
0
        public void Hashcodes_of_the_same_credentials_should_be_equal()
        {
            Guid id = Guid.NewGuid();
            string password = "******";
            var cred1 = new Credentials(id, password);
            var cred2 = new Credentials(id, password);

            Assert.Equal(cred1.GetHashCode(), cred2.GetHashCode());
        }
コード例 #2
0
        public AuthenticationFilterTests()
        {
            _requestCredentials = new Credentials(Guid.NewGuid(), "request");
            _adminCredentials = new Credentials(Guid.NewGuid(), "admin");
            _pullMonitorCredentials = new Credentials(Guid.NewGuid(), "pull");

            SetUpCredentialsProvider();
            SetUpTimeCoordinator();

            _endpoint = GetTestEndpoint();
        }
コード例 #3
0
 private HttpAuthenticationContext GetAuthContext(Credentials credentials)
 {
     var actionContext = new HttpActionContext(new HttpControllerContext()
     {
         Request = new HttpRequestMessage(),
     }, new ReflectedHttpActionDescriptor());
     var principal = new GenericPrincipal(new GenericIdentity("Basic"), null);
     var context = new HttpAuthenticationContext(actionContext, principal);
     
     context.Request.Headers.Authorization = new AuthenticationHeaderValue("Basic", $"{credentials.Id}:{credentials.Password}".ToBase64String());
     return context;
 }
コード例 #4
0
        public void AuthenticatoionFilter_should_not_authenticate_endpoint_with_invalid_credentials()
        {
            var invalidCredentials = new Credentials(Guid.NewGuid(), "invalid");
            var authContext = GetAuthContext(invalidCredentials);
            var filter = new AuthenticationFilter(_endpointRegistryMock.Object, _credentialsProviderMock.Object);

            filter.AuthenticateAsync(authContext, CancellationToken.None);

            Assert.Null(authContext.Principal);
        }