View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.fit.enduser;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  
24  import java.io.IOException;
25  import org.apache.syncope.client.enduser.pages.Dashboard;
26  import org.apache.syncope.client.enduser.pages.EditUser;
27  import org.apache.syncope.client.enduser.pages.Login;
28  import org.apache.syncope.client.enduser.pages.MustChangePassword;
29  import org.apache.syncope.client.enduser.pages.SelfResult;
30  import org.apache.syncope.client.ui.commons.Constants;
31  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPasswordFieldPanel;
32  import org.apache.syncope.common.lib.request.BooleanReplacePatchItem;
33  import org.apache.syncope.common.lib.request.UserUR;
34  import org.apache.syncope.common.lib.to.UserTO;
35  import org.apache.wicket.markup.html.WebMarkupContainer;
36  import org.apache.wicket.util.tester.FormTester;
37  import org.junit.jupiter.api.Test;
38  
39  public class AuthenticatedITCase extends AbstractEnduserITCase {
40  
41      @Test
42      public void login() throws IOException {
43          TESTER.startPage(Login.class);
44          TESTER.assertRenderedPage(Login.class);
45  
46          doLogin("bellini", "password");
47  
48          TESTER.assertNoErrorMessage();
49          TESTER.assertRenderedPage(Dashboard.class);
50      }
51  
52      @Test
53      public void mustChangePassword() {
54          UserTO mustchangepassword = USER_SERVICE.read("mustchangepassword");
55          USER_SERVICE.update(new UserUR.Builder(mustchangepassword.getKey()).
56                  mustChangePassword(new BooleanReplacePatchItem.Builder().value(Boolean.TRUE).build()).build());
57  
58          TESTER.startPage(Login.class);
59          doLogin("mustchangepassword", "password123");
60  
61          TESTER.assertRenderedPage(MustChangePassword.class);
62  
63          String changePwdForm = "body:contentWrapper:content:changePasswordPanel:changePassword";
64          TESTER.assertComponent(changePwdForm + ":password", AjaxPasswordFieldPanel.class);
65          TESTER.assertComponent(changePwdForm + ":confirmPassword", AjaxPasswordFieldPanel.class);
66  
67          FormTester formTester = TESTER.newFormTester(changePwdForm);
68  
69          assertNotNull(formTester);
70          // 1. set new password
71          formTester.setValue(findComponentById(changePwdForm + ":password", "passwordField"), "password124");
72          // 2. confirm password
73          formTester.setValue(findComponentById(changePwdForm + ":confirmPassword", "passwordField"), "password124");
74          // 3. submit form
75          TESTER.executeAjaxEvent(changePwdForm + ":submit", Constants.ON_CLICK);
76  
77          TESTER.assertRenderedPage(Login.class);
78  
79          TESTER.cleanupFeedbackMessages();
80  
81          doLogin("mustchangepassword", "password124");
82  
83          TESTER.assertNoErrorMessage();
84          TESTER.assertRenderedPage(Dashboard.class);
85      }
86  
87      @Test
88      public void selfUpdate() {
89          String username = "selfupdate";
90          String newEmail = "selfupdate@email.com";
91  
92          TESTER.startPage(Login.class);
93          doLogin(username, "password123");
94  
95          TESTER.assertComponent("body:contentWrapper:content:userProfileInfo:userProfile", WebMarkupContainer.class);
96  
97          TESTER.clickLink("body:sidebar:profileLI:profileUL:edituserLI:edituser", false);
98          TESTER.assertRenderedPage(EditUser.class);
99  
100         String form = "body:contentWrapper:content:editUserPanel:form";
101         FormTester formTester = TESTER.newFormTester(form);
102         formTester.setValue(
103                 "plainAttrsPanelCard:contentPanel:plainSchemas:schemas:4:panel:textField",
104                 newEmail);
105 
106         // check required fields were correctly set
107         TESTER.assertNoInfoMessage();
108         TESTER.assertNoErrorMessage();
109 
110         TESTER.executeAjaxEvent(form + ":submit", Constants.ON_CLICK);
111 
112         TESTER.assertRenderedPage(SelfResult.class);
113 
114         assertEquals(IS_FLOWABLE_ENABLED
115                 ? "active" : "created", USER_SERVICE.read(username).getStatus());
116         assertEquals(newEmail, USER_SERVICE.read(username).getPlainAttr("email").get().getValues().get(0));
117 
118         TESTER.cleanupFeedbackMessages();
119     }
120 }