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.shiro.test;
20  
21  import com.gargoylesoftware.htmlunit.ElementNotFoundException;
22  import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
23  import com.gargoylesoftware.htmlunit.WebAssert;
24  import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
25  import com.gargoylesoftware.htmlunit.html.HtmlForm;
26  import com.gargoylesoftware.htmlunit.html.HtmlInput;
27  import com.gargoylesoftware.htmlunit.html.HtmlPage;
28  import org.junit.Before;
29  import org.junit.Ignore;
30  import org.junit.Test;
31  
32  import java.io.IOException;
33  import java.net.MalformedURLException;
34  
35  @Ignore
36  public class ContainerIntegrationTest extends AbstractContainerTest {
37  
38      @Before
39      public void logOut() throws IOException {
40          // Make sure we are logged out
41          final HtmlPage homePage = webClient.getPage(getBaseUri());
42          try {
43              homePage.getAnchorByHref("/logout").click();
44          }
45          catch (ElementNotFoundException e) {
46              //Ignore
47          }
48      }
49  
50      @Test
51      public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
52  
53          HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
54          HtmlForm form = page.getFormByName("loginform");
55          form.<HtmlInput>getInputByName("username").setValueAttribute("root");
56          form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
57          page = form.<HtmlInput>getInputByName("submit").click();
58          // This'll throw an expection if not logged in
59          page.getAnchorByHref("/logout");
60      }
61  
62      @Test
63      public void logInAndRememberMe() throws Exception {
64          HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
65          HtmlForm form = page.getFormByName("loginform");
66          form.<HtmlInput>getInputByName("username").setValueAttribute("root");
67          form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
68          HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe");
69          checkbox.setChecked(true);
70          page = form.<HtmlInput>getInputByName("submit").click();
71          server.stop();
72          server.start();
73          page = webClient.getPage(getBaseUri());
74          // page.getAnchorByHref("/logout");
75          WebAssert.assertLinkPresentWithText(page, "Log out");
76          page = page.getAnchorByHref("/account").click();
77          // login page should be shown again - user remembered but not authenticated
78          WebAssert.assertFormPresent(page, "loginform");
79      }
80  
81  }