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.testsuite.Console;
22  import org.jboss.hal.testsuite.CrudOperations;
23  import org.jboss.hal.testsuite.container.WildFlyContainer;
24  import org.jboss.hal.testsuite.fragment.FormFragment;
25  import org.jboss.hal.testsuite.fragment.TableFragment;
26  import org.jboss.hal.testsuite.page.configuration.ElytronMappersDecodersPage;
27  import org.jboss.hal.testsuite.test.Manatoko;
28  import org.junit.jupiter.api.BeforeAll;
29  import org.junit.jupiter.api.BeforeEach;
30  import org.junit.jupiter.api.Test;
31  import org.testcontainers.junit.jupiter.Container;
32  import org.testcontainers.junit.jupiter.Testcontainers;
33  import org.wildfly.extras.creaper.core.online.operations.Operations;
34  import org.wildfly.extras.creaper.core.online.operations.Values;
35  
36  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
37  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
38  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.AGGREGATE_EVIDENCE_DECODER_CREATE;
39  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.AGGREGATE_EVIDENCE_DECODER_DELETE;
40  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.AGGREGATE_EVIDENCE_DECODER_READ;
41  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.AGGREGATE_EVIDENCE_DECODER_UPDATE;
42  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.ALT_NAME_TYPE;
43  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.ALT_NAME_TYPE_DIRECTORY_NAME;
44  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EVIDENCE_DECODERS;
45  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EVIDENCE_DECODER_ITEM;
46  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X500_EVIDENCE_DECODER_READ;
47  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X500_EVIDENCE_DECODER_UPDATE;
48  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X509_EVIDENCE_DECODER_READ;
49  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X509_EVIDENCE_DECODER_UPDATE;
50  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.aggregateEvidenceDecoderAddress;
51  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.x500EvidenceDecoderAddress;
52  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.x509EvidenceDecoderAddress;
53  import static org.junit.jupiter.api.Assertions.assertEquals;
54  
55  @Manatoko
56  @Testcontainers
57  class AggregateEvidenceDecoderTest {
58  
59      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
60  
61      @BeforeAll
62      static void setupModel() throws Exception {
63          ModelNode evidenceDecoders = new ModelNode()
64                  .add(X500_EVIDENCE_DECODER_READ)
65                  .add(X509_EVIDENCE_DECODER_READ);
66          Operations operations = new Operations(wildFly.managementClient());
67  
68          operations.add(x500EvidenceDecoderAddress(X500_EVIDENCE_DECODER_READ), Values.of(NAME, X500_EVIDENCE_DECODER_READ));
69          operations.add(x500EvidenceDecoderAddress(X500_EVIDENCE_DECODER_UPDATE), Values.of(NAME, X500_EVIDENCE_DECODER_UPDATE));
70  
71          operations.add(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_READ),
72                  Values.of(NAME, X509_EVIDENCE_DECODER_READ).and(ALT_NAME_TYPE, ALT_NAME_TYPE_DIRECTORY_NAME));
73          operations.add(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_UPDATE),
74                  Values.of(NAME, X509_EVIDENCE_DECODER_UPDATE).and(ALT_NAME_TYPE, ALT_NAME_TYPE_DIRECTORY_NAME));
75  
76          operations.add(aggregateEvidenceDecoderAddress(AGGREGATE_EVIDENCE_DECODER_READ),
77                  Values.of(EVIDENCE_DECODERS, evidenceDecoders));
78          operations.add(aggregateEvidenceDecoderAddress(AGGREGATE_EVIDENCE_DECODER_UPDATE),
79                  Values.of(EVIDENCE_DECODERS, evidenceDecoders));
80          operations.add(aggregateEvidenceDecoderAddress(AGGREGATE_EVIDENCE_DECODER_DELETE),
81                  Values.of(EVIDENCE_DECODERS, evidenceDecoders));
82      }
83  
84      @Inject Console console;
85      @Inject CrudOperations crud;
86      @Page ElytronMappersDecodersPage page;
87      TableFragment table;
88      FormFragment form;
89  
90      @BeforeEach
91      void prepare() {
92          page.navigate();
93          console.verticalNavigation().selectSecondary(EVIDENCE_DECODER_ITEM, "mappers-decoders-aggregate-evidence-decoder-item");
94          table = page.getAggregateEvidenceDecoderTable();
95          form = page.getAggregateEvidenceDecoderForm();
96          table.bind(form);
97      }
98  
99      @Test
100     void create() throws Exception {
101         crud.create(aggregateEvidenceDecoderAddress(AGGREGATE_EVIDENCE_DECODER_CREATE), table, form -> {
102             form.text(NAME, AGGREGATE_EVIDENCE_DECODER_CREATE);
103             form.list(EVIDENCE_DECODERS)
104                     .add(X500_EVIDENCE_DECODER_READ)
105                     .add(X509_EVIDENCE_DECODER_READ);
106         });
107     }
108 
109     @Test
110     void read() {
111         table.select(AGGREGATE_EVIDENCE_DECODER_READ);
112         assertEquals(X500_EVIDENCE_DECODER_READ + ", " + X509_EVIDENCE_DECODER_READ, form.value(EVIDENCE_DECODERS));
113     }
114 
115     @Test
116     void update() throws Exception {
117         ModelNode updatedEvidenceDecoders = new ModelNode()
118                 .add(X500_EVIDENCE_DECODER_UPDATE)
119                 .add(X509_EVIDENCE_DECODER_UPDATE);
120 
121         table.select(AGGREGATE_EVIDENCE_DECODER_UPDATE);
122         crud.update(aggregateEvidenceDecoderAddress(AGGREGATE_EVIDENCE_DECODER_UPDATE), form, f -> {
123             f.list(EVIDENCE_DECODERS).removeTags();
124             f.list(EVIDENCE_DECODERS)
125                     .add(X500_EVIDENCE_DECODER_UPDATE)
126                     .add(X509_EVIDENCE_DECODER_UPDATE);
127         }, resourceVerifier -> resourceVerifier.verifyAttribute(EVIDENCE_DECODERS, updatedEvidenceDecoders));
128     }
129 
130     @Test
131     void delete() throws Exception {
132         crud.delete(aggregateEvidenceDecoderAddress(AGGREGATE_EVIDENCE_DECODER_DELETE), table,
133                 AGGREGATE_EVIDENCE_DECODER_DELETE);
134     }
135 }