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.AddCredentialStore;
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.CREDENTIAL_STORE;
41  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
42  import static org.jboss.hal.dmr.ModelDescriptionConstants.RESOLVERS;
43  import static org.jboss.hal.resources.Ids.ELYTRON_OTHER_ITEM;
44  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
45  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.CREDENTIAL_STORE_CREATE;
46  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EXPRESSION_RESOLVER_CREATE;
47  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EXPRESSION_RESOLVER_DELETE;
48  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EXPRESSION_RESOLVER_READ;
49  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.EXPRESSION_RESOLVER_UPDATE;
50  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.SECRET_KEY;
51  import static org.jboss.hal.testsuite.fixtures.SecurityFixtures.expressionEncryptionAddress;
52  import static org.junit.jupiter.api.Assertions.assertEquals;
53  
54  @Manatoko
55  @Testcontainers
56  class ExpressionEncryptionResolverTest {
57  
58      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
59  
60      @BeforeAll
61      static void setupModel() throws Exception {
62          OnlineManagementClient client = wildFly.managementClient();
63          client.apply(new AddCredentialStore(CREDENTIAL_STORE_CREATE));
64  
65          ModelNode resolvers = new ModelNode();
66          resolvers.add(resolver(EXPRESSION_RESOLVER_READ));
67          resolvers.add(resolver(EXPRESSION_RESOLVER_UPDATE));
68          resolvers.add(resolver(EXPRESSION_RESOLVER_DELETE));
69  
70          Operations operations = new Operations(client);
71          operations.add(expressionEncryptionAddress(), Values.of(RESOLVERS, resolvers));
72      }
73  
74      private static ModelNode resolver(String name) {
75          ModelNode resolver = new ModelNode();
76          resolver.get(NAME).set(name);
77          resolver.get(CREDENTIAL_STORE).set(CREDENTIAL_STORE_CREATE);
78          resolver.get(SECRET_KEY).set(Random.name());
79          return resolver;
80      }
81  
82      @Inject Console console;
83      @Inject CrudOperations crud;
84      @Page ElytronOtherSettingsPage page;
85      TableFragment table;
86      FormFragment form;
87  
88      @BeforeEach
89      void prepare() {
90          page.navigate();
91          console.verticalNavigation().selectSecondary(ELYTRON_OTHER_ITEM, Ids.ELYTRON_EXPRESSION);
92          table = page.getExpressionResolverTable();
93          form = page.getExpressionResolverForm();
94          table.bind(form);
95      }
96  
97      @Test
98      void create() throws Exception {
99          crud.create(expressionEncryptionAddress(), table, f -> {
100             f.text(CREDENTIAL_STORE, CREDENTIAL_STORE_CREATE);
101             f.text(NAME, EXPRESSION_RESOLVER_CREATE);
102             f.text(SECRET_KEY, Random.name());
103         }, resourceVerifier -> resourceVerifier.verifyListAttributeContainsSingleValue(RESOLVERS, NAME,
104                 EXPRESSION_RESOLVER_CREATE));
105     }
106 
107     @Test
108     void read() {
109         table.select(EXPRESSION_RESOLVER_READ);
110         assertEquals(EXPRESSION_RESOLVER_READ, form.value(NAME));
111     }
112 
113     @Test
114     void update() throws Exception {
115         String secretKey = Random.name();
116         table.select(EXPRESSION_RESOLVER_UPDATE);
117         crud.update(expressionEncryptionAddress(), form, f -> f.text(SECRET_KEY, secretKey),
118                 resourceVerifier -> resourceVerifier.verifyListAttributeContainsSingleValue(RESOLVERS, SECRET_KEY, secretKey));
119     }
120 
121     @Test
122     void delete() throws Exception {
123         crud.delete(expressionEncryptionAddress(), table, EXPRESSION_RESOLVER_DELETE, resourceVerifier -> resourceVerifier
124                 .verifyListAttributeDoesNotContainSingleValue(RESOLVERS, NAME, EXPRESSION_RESOLVER_DELETE));
125     }
126 }