Пример #1
0
        public void SetBasicAuthorizationDetectionMethod(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthorizationComponent sut,
            int contextId,
            BasicAuthorizationDetectionMethod basicAuthorizationDetectionMethod)
        {
            // ARRANGE
            httpClientMock.SetupApiCall(sut, CallType.Action, "setBasicAuthorizationDetectionMethod",
                                        new Parameters
            {
                { "contextId", contextId },
                { "headerRegex", basicAuthorizationDetectionMethod.HeaderRegex },
                { "bodyRegex", basicAuthorizationDetectionMethod.BodyRegex },
                { "statusCode", basicAuthorizationDetectionMethod.StatusCode },
                { "logicalOperator", basicAuthorizationDetectionMethod.LogicalOperator }
            })
            .ReturnsOkResult()
            .Verifiable();

            // ACT
            sut.SetBasicAuthorizationDetectionMethod(contextId, basicAuthorizationDetectionMethod);

            // ASSERT
            httpClientMock.Verify();
        }
Пример #2
0
        public void GetAuthorizationDetectionMethod(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthorizationComponent sut,
            int contextId,
            BasicAuthorizationDetectionMethod basicAuthorizationDetectionMethod)
        {
            // ARRANGE
            var json = JObject.FromObject(basicAuthorizationDetectionMethod);

            json.Add("methodType", "basic");
            httpClientMock.SetupApiCall(sut, CallType.View, "getAuthorizationDetectionMethod",
                                        new Parameters
            {
                { "contextId", contextId }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetAuthorizationDetectionMethod(contextId);

            // ASSERT
            result.ShouldBeEquivalentTo(basicAuthorizationDetectionMethod);
            httpClientMock.Verify();
        }
Пример #3
0
 public ZapClient(string host, int port, Protocols protocol = Protocols.http)
 {
     Protocol          = protocol;
     Host              = host;
     Port              = port;
     Acsrf             = new AcsrfComponent(this);
     AjaxSpider        = new AjaxSpiderComponent(this);
     Ascan             = new AscanComponent(this);
     Authentication    = new AuthenticationComponent(this);
     Authorization     = new AuthorizationComponent(this);
     Autoupdate        = new AutoupdateComponent(this);
     Break             = new BreakComponent(this);
     Context           = new ContextComponent(this);
     Core              = new CoreComponent(this);
     ForcedUser        = new ForcedUserComponent(this);
     HttpSessions      = new HttpSessionsComponent(this);
     Params            = new ParamsComponent(this);
     Pscan             = new PscanComponent(this);
     Reveal            = new RevealComponent(this);
     Script            = new ScriptComponent(this);
     Search            = new SearchComponent(this);
     Selenium          = new SeleniumComponent(this);
     SessionManagement = new SessionManagementComponent(this);
     Spider            = new SpiderComponent(this);
     Users             = new UsersComponent(this);
 }
Пример #4
0
        public void ComponentName(
            [Greedy] AuthorizationComponent sut)
        {
            // ACT
            var result = sut.ComponentName;

            // ASSERT
            result.Should().Be("authorization");
        }
Пример #5
0
        public void GetAuthorizationDetectionMethod_UnsupportedMethodType(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] AuthorizationComponent sut,
            int contextId)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("methodType", "alternative"));

            httpClientMock.SetupApiCall(sut, CallType.View, "getAuthorizationDetectionMethod",
                                        new Parameters
            {
                { "contextId", contextId }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            Action act = () => sut.GetAuthorizationDetectionMethod(contextId);

            // ASSERT
            act.ShouldThrow <ZapException>().WithMessage(Resources.UnsupportedAuthorizationDetectionMethod);
            httpClientMock.Verify();
        }