严智鑫
2025-11-13 945bc394f40d8af1072a53da9a94f24207124e6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.northglass.functional.gui;
 
import static org.assertj.core.api.Assertions.*;
 
import org.junit.Test;
import org.openqa.selenium.By;
import com.northglass.functional.BaseSeleniumTestCase;
 
/**
 * 系统安全控制的功能测试, 测试主要用户故事.
 * 
 * @author calvin
 */
public class SecurityFT extends BaseSeleniumTestCase {
 
    /**
     * 测试匿名用户访问系统时的行为.
     */
    @Test
    public void anonymousUserAccessSystem() {
        // 访问退出登录页面,退出之前的登录
        s.open("/logout");
        s.waitForTitleContains("登录页");
 
        // 访问任意页面会跳转到登录界面
        s.open("/task");
        s.waitForTitleContains("登录页");
    }
 
    /**
     * 测试普通用户访问管理员的用户管理功能时代行为。
     */
    @Test
    public void userTryToManageUsers() {
        loginAsUserIfNecessary();
        s.open("/admin/user");
        assertThat(s.getTitle()).isEqualTo("Error 401 Unauthorized");
    }
 
    /**
     * 登录错误的用户名密码.
     */
    @Test
    public void loginWithWrongPassword() {
        s.open("/logout");
        s.type(By.name("username"), "wrongUser");
        s.type(By.name("password"), "WrongPassword");
        s.check(By.name("rememberMe"));
        s.click(By.id("submit_btn"));
 
        s.waitForTitleContains("登录页");
        assertThat(s.isTextPresent("登录失败,请重试.")).isTrue();
    }
}