View Javadoc
1   /*
2    *  Copyright 2022 Red Hat
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.jboss.hal.testsuite.test.configuration.web;
17  
18  import org.jboss.arquillian.core.api.annotation.Inject;
19  import org.jboss.arquillian.graphene.page.Page;
20  import org.jboss.hal.testsuite.CrudOperations;
21  import org.jboss.hal.testsuite.Random;
22  import org.jboss.hal.testsuite.command.AddHttpAuthenticationFactory;
23  import org.jboss.hal.testsuite.command.AddSecurityDomain;
24  import org.jboss.hal.testsuite.container.WildFlyContainer;
25  import org.jboss.hal.testsuite.page.configuration.ApplicationSecurityDomainPage;
26  import org.jboss.hal.testsuite.test.Manatoko;
27  import org.junit.jupiter.api.BeforeAll;
28  import org.junit.jupiter.api.Test;
29  import org.testcontainers.junit.jupiter.Container;
30  import org.testcontainers.junit.jupiter.Testcontainers;
31  import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
32  import org.wildfly.extras.creaper.core.online.operations.Operations;
33  import org.wildfly.extras.creaper.core.online.operations.Values;
34  
35  import static org.jboss.hal.dmr.ModelDescriptionConstants.HTTP_AUTHENTICATION_FACTORY;
36  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
37  import static org.jboss.hal.dmr.ModelDescriptionConstants.SECURITY_DOMAIN;
38  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
39  import static org.jboss.hal.testsuite.fixtures.WebFixtures.APPLICATION_SECURITY_DOMAIN_HAF;
40  import static org.jboss.hal.testsuite.fixtures.WebFixtures.APPLICATION_SECURITY_DOMAIN_SD;
41  import static org.jboss.hal.testsuite.fixtures.WebFixtures.APPLICATION_SECURITY_DOMAIN_UPDATE;
42  import static org.jboss.hal.testsuite.fixtures.WebFixtures.ENABLE_JACC;
43  import static org.jboss.hal.testsuite.fixtures.WebFixtures.ENABLE_JASPI;
44  import static org.jboss.hal.testsuite.fixtures.WebFixtures.INTEGRATED_JASPI;
45  import static org.jboss.hal.testsuite.fixtures.WebFixtures.OVERRIDE_DEPLOYMENT_CONFIG;
46  import static org.jboss.hal.testsuite.fixtures.WebFixtures.applicationSecurityDomainAddress;
47  
48  @Manatoko
49  @Testcontainers
50  class ApplicationSecurityDomainTest {
51  
52      private static final String SECURITY_DOMAIN_NAME = Random.name();
53      private static final String HTTP_AUTHENTICATION_FACTORY_NAME = Random.name();
54  
55      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
56      static Operations operations;
57  
58      @BeforeAll
59      static void setupModel() throws Exception {
60          OnlineManagementClient client = wildFly.managementClient();
61          client.apply(new AddSecurityDomain(SECURITY_DOMAIN_NAME));
62          client.apply(new AddHttpAuthenticationFactory(HTTP_AUTHENTICATION_FACTORY_NAME));
63  
64          operations = new Operations(client);
65          operations.add(applicationSecurityDomainAddress(APPLICATION_SECURITY_DOMAIN_UPDATE),
66                  Values.of(HTTP_AUTHENTICATION_FACTORY, HTTP_AUTHENTICATION_FACTORY_NAME));
67          operations.add(applicationSecurityDomainAddress(APPLICATION_SECURITY_DOMAIN_HAF),
68                  Values.of(HTTP_AUTHENTICATION_FACTORY, HTTP_AUTHENTICATION_FACTORY_NAME));
69          operations.add(applicationSecurityDomainAddress(APPLICATION_SECURITY_DOMAIN_SD),
70                  Values.of(SECURITY_DOMAIN, SECURITY_DOMAIN_NAME));
71      }
72  
73      @Page ApplicationSecurityDomainPage page;
74      @Inject CrudOperations crud;
75  
76      @Test
77      void edit() throws Exception {
78          page.navigate(NAME, APPLICATION_SECURITY_DOMAIN_UPDATE);
79          crud.update(applicationSecurityDomainAddress(APPLICATION_SECURITY_DOMAIN_UPDATE), page.getAttributesForm(),
80                  f -> {
81                      f.flip(ENABLE_JACC, true);
82                      f.flip(ENABLE_JASPI, false);
83                      f.flip(INTEGRATED_JASPI, true);
84                      f.flip(OVERRIDE_DEPLOYMENT_CONFIG, false);
85                  },
86                  resourceVerifier -> {
87                      resourceVerifier.verifyAttribute(ENABLE_JACC, true);
88                      resourceVerifier.verifyAttribute(ENABLE_JASPI, false);
89                      resourceVerifier.verifyAttribute(INTEGRATED_JASPI, true);
90                      resourceVerifier.verifyAttribute(OVERRIDE_DEPLOYMENT_CONFIG, false);
91                  });
92      }
93  
94      @Test
95      void switchToSecurityDomain() throws Exception {
96          page.navigate(NAME, APPLICATION_SECURITY_DOMAIN_HAF);
97          crud.update(applicationSecurityDomainAddress(APPLICATION_SECURITY_DOMAIN_HAF), page.getAttributesForm(),
98                  form -> {
99                      form.text(SECURITY_DOMAIN, SECURITY_DOMAIN_NAME);
100                     form.clear(HTTP_AUTHENTICATION_FACTORY);
101                 },
102                 resourceVerifier -> resourceVerifier.verifyAttribute(SECURITY_DOMAIN, SECURITY_DOMAIN_NAME));
103     }
104 
105     @Test
106     void switchToHttpAuthenticationFactory() throws Exception {
107         page.navigate(NAME, APPLICATION_SECURITY_DOMAIN_SD);
108         crud.update(applicationSecurityDomainAddress(APPLICATION_SECURITY_DOMAIN_SD), page.getAttributesForm(),
109                 form -> {
110                     form.text(HTTP_AUTHENTICATION_FACTORY, HTTP_AUTHENTICATION_FACTORY_NAME);
111                     form.clear(SECURITY_DOMAIN);
112                 },
113                 resourceVerifier -> resourceVerifier.verifyAttribute(HTTP_AUTHENTICATION_FACTORY,
114                         HTTP_AUTHENTICATION_FACTORY_NAME));
115     }
116 }