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.hal.testsuite.Console;
21  import org.jboss.hal.testsuite.CrudOperations;
22  import org.jboss.hal.testsuite.container.WildFlyContainer;
23  import org.jboss.hal.testsuite.fragment.FormFragment;
24  import org.jboss.hal.testsuite.fragment.TableFragment;
25  import org.jboss.hal.testsuite.page.configuration.ElytronMappersDecodersPage;
26  import org.jboss.hal.testsuite.test.Manatoko;
27  import org.junit.jupiter.api.BeforeAll;
28  import org.junit.jupiter.api.BeforeEach;
29  import org.junit.jupiter.api.Test;
30  import org.testcontainers.junit.jupiter.Container;
31  import org.testcontainers.junit.jupiter.Testcontainers;
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.NAME;
36  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
37  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.ALT_NAME_TYPE;
38  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.ALT_NAME_TYPE_DIRECTORY_NAME;
39  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.ALT_NAME_TYPE_RFC822_NAME;
40  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EVIDENCE_DECODER_ITEM;
41  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.SEGMENT;
42  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X509_EVIDENCE_DECODER_CREATE;
43  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X509_EVIDENCE_DECODER_DELETE;
44  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X509_EVIDENCE_DECODER_READ;
45  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.X509_EVIDENCE_DECODER_UPDATE;
46  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.x509EvidenceDecoderAddress;
47  import static org.junit.jupiter.api.Assertions.assertEquals;
48  
49  @Manatoko
50  @Testcontainers
51  class X509EvidenceDecoderTest {
52  
53      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
54  
55      @BeforeAll
56      static void setupModel() throws Exception {
57          Operations operations = new Operations(wildFly.managementClient());
58          operations.add(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_READ),
59                  Values.of(NAME, X509_EVIDENCE_DECODER_READ).and(ALT_NAME_TYPE, ALT_NAME_TYPE_DIRECTORY_NAME));
60          operations.add(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_UPDATE),
61                  Values.of(NAME, X509_EVIDENCE_DECODER_UPDATE).and(ALT_NAME_TYPE, ALT_NAME_TYPE_DIRECTORY_NAME));
62          operations.add(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_DELETE),
63                  Values.of(NAME, X509_EVIDENCE_DECODER_DELETE).and(ALT_NAME_TYPE, ALT_NAME_TYPE_DIRECTORY_NAME));
64      }
65  
66      @Inject Console console;
67      @Inject CrudOperations crud;
68      @Page ElytronMappersDecodersPage page;
69      TableFragment table;
70      FormFragment form;
71  
72      @BeforeEach
73      void prepare() {
74          page.navigate();
75          console.verticalNavigation().selectSecondary(EVIDENCE_DECODER_ITEM,
76                  "mappers-decoders-x509-subject-alt-name-evidence-decoder-item");
77          table = page.getX509EvidenceDecoderTable();
78          form = page.getX509EvidenceDecoderForm();
79          table.bind(form);
80      }
81  
82      @Test
83      void create() throws Exception {
84          crud.create(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_CREATE), table, form -> {
85              form.text(NAME, X509_EVIDENCE_DECODER_CREATE);
86              form.select(ALT_NAME_TYPE, ALT_NAME_TYPE_DIRECTORY_NAME);
87          });
88      }
89  
90      @Test
91      void read() {
92          table.select(X509_EVIDENCE_DECODER_READ);
93          assertEquals(ALT_NAME_TYPE_DIRECTORY_NAME, form.value(ALT_NAME_TYPE));
94      }
95  
96      @Test
97      void update() throws Exception {
98          table.select(X509_EVIDENCE_DECODER_UPDATE);
99          crud.update(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_UPDATE), form, f -> {
100             f.select(ALT_NAME_TYPE, ALT_NAME_TYPE_RFC822_NAME);
101             f.number(SEGMENT, 23);
102         }, resourceVerifier -> {
103             resourceVerifier.verifyAttribute(ALT_NAME_TYPE, ALT_NAME_TYPE_RFC822_NAME);
104             resourceVerifier.verifyAttribute(SEGMENT, 23);
105         });
106     }
107 
108     @Test
109     void delete() throws Exception {
110         crud.delete(x509EvidenceDecoderAddress(X509_EVIDENCE_DECODER_DELETE), table, X509_EVIDENCE_DECODER_DELETE);
111     }
112 }