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.security;
17  
18  import org.jboss.arquillian.core.api.annotation.Inject;
19  import org.jboss.arquillian.graphene.page.Page;
20  import org.jboss.dmr.ModelNode;
21  import org.jboss.hal.resources.Ids;
22  import org.jboss.hal.testsuite.Console;
23  import org.jboss.hal.testsuite.CrudOperations;
24  import org.jboss.hal.testsuite.Random;
25  import org.jboss.hal.testsuite.command.AddKeyStore;
26  import org.jboss.hal.testsuite.container.WildFlyContainer;
27  import org.jboss.hal.testsuite.fragment.FormFragment;
28  import org.jboss.hal.testsuite.fragment.TableFragment;
29  import org.jboss.hal.testsuite.page.configuration.ElytronOtherSettingsPage;
30  import org.jboss.hal.testsuite.test.Manatoko;
31  import org.junit.jupiter.api.BeforeAll;
32  import org.junit.jupiter.api.BeforeEach;
33  import org.junit.jupiter.api.Test;
34  import org.testcontainers.junit.jupiter.Container;
35  import org.testcontainers.junit.jupiter.Testcontainers;
36  import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
37  import org.wildfly.extras.creaper.core.online.operations.Operations;
38  import org.wildfly.extras.creaper.core.online.operations.Values;
39  
40  import static org.jboss.hal.dmr.ModelDescriptionConstants.KEY_STORE;
41  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
42  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.OCSP;
43  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.RESPONDER;
44  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.TRUST_MANAGER_CREATE;
45  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.TRUST_MANAGER_DELETE;
46  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.TRUST_MANAGER_UPDATE;
47  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.trustManagerAddress;
48  
49  @Manatoko
50  @Testcontainers
51  class TrustManagerOCSPTest {
52  
53      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
54  
55      @BeforeAll
56      static void setupModel() throws Exception {
57          ModelNode ocspModel = new ModelNode();
58          ocspModel.get(RESPONDER).set("responder");
59  
60          OnlineManagementClient client = wildFly.managementClient();
61          String keyStore = Random.name();
62          client.apply(new AddKeyStore(keyStore));
63  
64          Operations operations = new Operations(wildFly.managementClient());
65          operations.add(trustManagerAddress(TRUST_MANAGER_CREATE), Values.of(KEY_STORE, keyStore));
66          operations.add(trustManagerAddress(TRUST_MANAGER_UPDATE), Values.of(KEY_STORE, keyStore));
67          operations.writeAttribute(trustManagerAddress(TRUST_MANAGER_UPDATE), OCSP, ocspModel);
68          operations.add(trustManagerAddress(TRUST_MANAGER_DELETE), Values.of(KEY_STORE, keyStore));
69          operations.writeAttribute(trustManagerAddress(TRUST_MANAGER_DELETE), OCSP, ocspModel);
70      }
71  
72      @Inject Console console;
73      @Inject CrudOperations crud;
74      @Page ElytronOtherSettingsPage page;
75      TableFragment table;
76      FormFragment form;
77  
78      @BeforeEach
79      void prepare() {
80          page.navigate();
81          console.verticalNavigation().selectSecondary(Ids.ELYTRON_SSL_ITEM, "elytron-trust-manager-item");
82          table = page.getTrustManagerTable();
83          form = page.getTrustManagerOCSPForm();
84          table.bind(form);
85      }
86  
87      @Test
88      void create() throws Exception {
89          table.select(TRUST_MANAGER_CREATE);
90          page.getTrustManagerTab().select("elytron-trust-manager-ocsp-tab");
91          crud.createSingleton(trustManagerAddress(TRUST_MANAGER_CREATE), form);
92      }
93  
94      @Test
95      void update() throws Exception {
96          String responder = Random.name();
97          table.select(TRUST_MANAGER_UPDATE);
98          page.getTrustManagerTab().select("elytron-trust-manager-ocsp-tab");
99          crud.update(trustManagerAddress(TRUST_MANAGER_UPDATE), form, f -> {
100             f.text(RESPONDER, responder);
101         }, resourceVerifier -> resourceVerifier.verifyAttribute(OCSP + "." + RESPONDER, responder));
102     }
103 
104     @Test
105     void delete() throws Exception {
106         table.select(TRUST_MANAGER_DELETE);
107         page.getTrustManagerTab().select("elytron-trust-manager-ocsp-tab");
108         crud.deleteSingleton(trustManagerAddress(TRUST_MANAGER_DELETE), form,
109                 resourceVerifier -> resourceVerifier.verifyAttributeIsUndefined(OCSP));
110     }
111 }