From 292972c0ce0a9904206d9d99664339f7af9521ee Mon Sep 17 00:00:00 2001
From: Sunflower613 <2963707761@qq.com>
Date: Tue, 19 Mar 2024 14:59:36 +0800
Subject: [PATCH 1/6] Fix bug 528
---
app/templates/login.html | 5 +++++
app/templates/reset.html | 5 +++++
app/templates/signup.html | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/app/templates/login.html b/app/templates/login.html
index b8eb118..169c669 100644
--- a/app/templates/login.html
+++ b/app/templates/login.html
@@ -15,6 +15,11 @@
alert('输入不能为空!');
return false;
}
+ let reg = /^\S*$/; // 正则表达式,用于匹配不包含空格的字符串
+ if (!reg.test(password)) {
+ alert('输入不能包含空格!');
+ return false;
+ }
$.post(
"/login", {'username': username, 'password': password},
function (response) {
diff --git a/app/templates/reset.html b/app/templates/reset.html
index 3425c97..4834695 100644
--- a/app/templates/reset.html
+++ b/app/templates/reset.html
@@ -12,6 +12,11 @@
alert('输入不能为空!');
return false;
}
+ let reg = /^\S*$/; // 正则表达式,用于匹配不包含空格的字符串
+ if (!reg.test(old_password) || !reg.test(new_password)) {
+ alert('输入不能包含空格!');
+ return false;
+ }
if (new_password !== re_new_password) {
alert('新密码不匹配,请重新输入');
return false;
diff --git a/app/templates/signup.html b/app/templates/signup.html
index 5b3aafe..8d688f3 100644
--- a/app/templates/signup.html
+++ b/app/templates/signup.html
@@ -16,6 +16,11 @@ You're logged in already! Logout.
alert('输入不能为空!');
return false;
}
+ let reg = /^\S*$/; // 正则表达式,用于匹配不包含空格的字符串
+ if (!reg.test(password) || !reg.test(password2)) {
+ alert('输入不能包含空格!');
+ return false;
+ }
if (password !== password2) {
alert('确认密码与输入密码不一致!');
return false;
From 85a3faaa9f96370af30f4ef5c418f592f86dbc77 Mon Sep 17 00:00:00 2001
From: Sunflower613 <2963707761@qq.com>
Date: Sat, 6 Apr 2024 00:18:44 +0800
Subject: [PATCH 2/6] Fix bug 528
---
app/templates/login.html | 9 +++--
app/templates/reset.html | 9 +++--
app/templates/signup.html | 9 +++--
app/test/test_login_password_with_space.py | 35 ++++++++++++++++++
app/test/test_reset_password_with_space.py | 35 ++++++++++++++++++
app/test/test_signup_password_with_space.py | 39 +++++++++++++++++++++
6 files changed, 121 insertions(+), 15 deletions(-)
create mode 100644 app/test/test_login_password_with_space.py
create mode 100644 app/test/test_reset_password_with_space.py
create mode 100644 app/test/test_signup_password_with_space.py
diff --git a/app/templates/login.html b/app/templates/login.html
index 169c669..b0806b6 100644
--- a/app/templates/login.html
+++ b/app/templates/login.html
@@ -15,11 +15,10 @@
alert('输入不能为空!');
return false;
}
- let reg = /^\S*$/; // 正则表达式,用于匹配不包含空格的字符串
- if (!reg.test(password)) {
- alert('输入不能包含空格!');
- return false;
- }
+ if (password.includes(' ')) {
+ alert('输入不能包含空格!');
+ return false;
+ }
$.post(
"/login", {'username': username, 'password': password},
function (response) {
diff --git a/app/templates/reset.html b/app/templates/reset.html
index 4834695..408e001 100644
--- a/app/templates/reset.html
+++ b/app/templates/reset.html
@@ -12,11 +12,10 @@
alert('输入不能为空!');
return false;
}
- let reg = /^\S*$/; // 正则表达式,用于匹配不包含空格的字符串
- if (!reg.test(old_password) || !reg.test(new_password)) {
- alert('输入不能包含空格!');
- return false;
- }
+ if (old_password.includes(' ') || new_password.includes(' ')) {
+ alert('输入不能包含空格!');
+ return false;
+ }
if (new_password !== re_new_password) {
alert('新密码不匹配,请重新输入');
return false;
diff --git a/app/templates/signup.html b/app/templates/signup.html
index 8d688f3..6b5db6e 100644
--- a/app/templates/signup.html
+++ b/app/templates/signup.html
@@ -16,11 +16,10 @@ You're logged in already! Logout.
alert('输入不能为空!');
return false;
}
- let reg = /^\S*$/; // 正则表达式,用于匹配不包含空格的字符串
- if (!reg.test(password) || !reg.test(password2)) {
- alert('输入不能包含空格!');
- return false;
- }
+ if (password.includes(' ') || password2.includes(' ')) {
+ alert('输入不能包含空格!');
+ return false;
+ }
if (password !== password2) {
alert('确认密码与输入密码不一致!');
return false;
diff --git a/app/test/test_login_password_with_space.py b/app/test/test_login_password_with_space.py
new file mode 100644
index 0000000..9be5118
--- /dev/null
+++ b/app/test/test_login_password_with_space.py
@@ -0,0 +1,35 @@
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+from selenium.webdriver.common.keys import Keys
+
+import time
+
+# 初始化WebDriver
+driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
+driver.implicitly_wait(10)
+
+
+# 测试登录页面输入密码包含空格的情况
+def test_login_password_with_space():
+ try:
+ driver.get("http://121.4.94.30:91/login")
+
+ # 输入用户名
+ username_elem = driver.find_element_by_name('username')
+ username_elem.send_keys("test_user")
+
+ # 输入包含空格的密码
+ password_elem = driver.find_element_by_name('password')
+ password_elem.send_keys("password with space")
+
+ # 提交登录表单
+ password_elem.send_keys(Keys.RETURN)
+
+ # 等待一段时间确保页面加载完成
+ time.sleep(2)
+
+ # 检查是否弹出警告框
+ alert = driver.switch_to.alert
+ assert "输入不能包含空格!" in alert.text
+ finally:
+ driver.quit()
\ No newline at end of file
diff --git a/app/test/test_reset_password_with_space.py b/app/test/test_reset_password_with_space.py
new file mode 100644
index 0000000..b2a7ac0
--- /dev/null
+++ b/app/test/test_reset_password_with_space.py
@@ -0,0 +1,35 @@
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+from selenium.webdriver.common.keys import Keys
+
+import time
+
+# 初始化WebDriver
+driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
+driver.implicitly_wait(10)
+
+
+# 测试重设密码页面输入旧密码或新密码包含空格的情况
+def test_reset_password_with_space():
+ try:
+ driver.get("http://121.4.94.30:91/reset")
+
+ # 输入旧密码
+ old_password_elem = driver.find_element_by_name('old_password')
+ old_password_elem.send_keys("old password with space")
+
+ # 输入新密码
+ new_password_elem = driver.find_element_by_name('new_password')
+ new_password_elem.send_keys("new password with space")
+
+ # 提交重设密码表单
+ new_password_elem.send_keys(Keys.RETURN)
+
+ # 等待一段时间确保页面加载完成
+ time.sleep(2)
+
+ # 检查是否弹出警告框
+ alert = driver.switch_to.alert
+ assert "输入不能包含空格!" in alert.text
+ finally:
+ driver.quit()
diff --git a/app/test/test_signup_password_with_space.py b/app/test/test_signup_password_with_space.py
new file mode 100644
index 0000000..6d5f066
--- /dev/null
+++ b/app/test/test_signup_password_with_space.py
@@ -0,0 +1,39 @@
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+from selenium.webdriver.common.keys import Keys
+
+import time
+
+# 初始化WebDriver
+driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
+driver.implicitly_wait(10)
+
+
+# 测试注册页面输入密码包含空格的情况
+def test_signup_password_with_space():
+ try:
+ driver.get("http://121.4.94.30:91/signup")
+
+ # 输入用户名
+ username_elem = driver.find_element_by_name('username')
+ username_elem.send_keys("new_user")
+
+ # 输入包含空格的密码
+ password_elem = driver.find_element_by_name('password')
+ password_elem.send_keys("password with space")
+
+ # 再次输入密码
+ password2_elem = driver.find_element_by_name('password2')
+ password2_elem.send_keys("password with space")
+
+ # 提交注册表单
+ password2_elem.send_keys(Keys.RETURN)
+
+ # 等待一段时间确保页面加载完成
+ time.sleep(2)
+
+ # 检查是否弹出警告框
+ alert = driver.switch_to.alert
+ assert "输入不能包含空格!" in alert.text
+ finally:
+ driver.quit()
From 426d131f6456500517cd9228faa6958f8fdc7f87 Mon Sep 17 00:00:00 2001
From: Sunflower613 <2963707761@qq.com>
Date: Mon, 15 Apr 2024 06:12:41 +0800
Subject: [PATCH 3/6] Fix Text Files
---
app/templates/login.html | 4 ++
app/templates/reset.html | 4 ++
app/templates/signup.html | 4 ++
app/test/test_bug528_tangjiao.py | 107 +++++++++++++++++++++++++++++++
4 files changed, 119 insertions(+)
create mode 100644 app/test/test_bug528_tangjiao.py
diff --git a/app/templates/login.html b/app/templates/login.html
index b8eb118..b0806b6 100644
--- a/app/templates/login.html
+++ b/app/templates/login.html
@@ -15,6 +15,10 @@
alert('输入不能为空!');
return false;
}
+ if (password.includes(' ')) {
+ alert('输入不能包含空格!');
+ return false;
+ }
$.post(
"/login", {'username': username, 'password': password},
function (response) {
diff --git a/app/templates/reset.html b/app/templates/reset.html
index 3425c97..1ba46ea 100644
--- a/app/templates/reset.html
+++ b/app/templates/reset.html
@@ -20,6 +20,10 @@
alert('密码过于简单。(密码长度至少4位)');
return false;
}
+ if (old_password.includes(' ') || new_password.includes(' ')) {
+ alert('输入不能包含空格!');
+ return false;
+ }
$.post("/reset", {'old-password': old_password, 'new-password': new_password},
function (response) {
if (response.status === '1') {
diff --git a/app/templates/signup.html b/app/templates/signup.html
index 5b3aafe..67984fe 100644
--- a/app/templates/signup.html
+++ b/app/templates/signup.html
@@ -24,6 +24,10 @@ You're logged in already! Logout.
alert('密码过于简单。(密码长度至少4位)');
return false;
}
+ if (password.includes(' ') || password2.includes(' ')) {
+ alert('输入不能包含空格!');
+ return false;
+ }
$.post("/signup", {'username': username, 'password': password},
function (response) {
if (response.status === '0') {
diff --git a/app/test/test_bug528_tangjiao.py b/app/test/test_bug528_tangjiao.py
new file mode 100644
index 0000000..c732009
--- /dev/null
+++ b/app/test/test_bug528_tangjiao.py
@@ -0,0 +1,107 @@
+import pytest
+from selenium import webdriver
+from selenium.webdriver.common.by import By
+from selenium.webdriver.common.keys import Keys
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.common.exceptions import NoSuchElementException, TimeoutException
+
+# 使用 Pytest 的 fixture 初始化 WebDriver 和 URL
+@pytest.fixture(scope="module")
+def driver():
+ # 初始化WebDriver
+ driver = webdriver.Edge(executable_path=r'D:\codeapp\python-3.8.5\Lib\site-packages\selenium\webdriver\edge\MicrosoftWebDriver.exe')
+ driver.implicitly_wait(10)
+ yield driver # yield 语句之后的代码在测试用例执行完毕后运行
+ driver.quit() # 测试用例执行完毕后关闭 WebDriver
+
+@pytest.fixture(scope="module")
+def URL():
+ return 'http://127.0.0.1:5000'
+
+# 测试登录页面输入密码包含空格的情况
+def test_login_password_with_space(driver, URL):
+ try:
+ driver.get(URL+"/login")
+
+ # 输入用户名
+ username_elem = driver.find_element_by_id('username')
+ username_elem.send_keys("test_user")
+
+ # 输入包含空格的密码
+ password_elem = driver.find_element_by_id('password')
+ password_elem.send_keys("password with space")
+
+ # 提交登录表单
+ elem = driver.find_element_by_class_name('btn') # 找到提交按钮
+ elem.click()
+
+ # 显式等待直到警告框出现
+ WebDriverWait(driver, 10).until(EC.alert_is_present())
+
+ # 检查是否弹出警告框
+ alert = driver.switch_to.alert
+ assert "输入不能包含空格!" in alert.text
+ except (NoSuchElementException, TimeoutException) as e:
+ pytest.fail("页面元素未找到或超时: {}".format(e))
+
+
+# 测试注册页面输入密码包含空格的情况
+
+def test_signup_password_with_space(driver, URL):
+ try:
+ driver.get(URL+"/signup")
+
+ # 输入用户名
+ username_elem = driver.find_element_by_id('username')
+ username_elem.send_keys("new_user")
+
+ # 输入包含空格的密码
+ password_elem = driver.find_element_by_id('password')
+ password_elem.send_keys("password with space")
+
+ # 再次输入密码
+ password2_elem = driver.find_element_by_id('password2')
+ password2_elem.send_keys("password with space")
+
+ # 提交注册表单
+ elem = driver.find_element_by_class_name('btn') # 找到提交按钮
+ elem.click()
+
+ # 显式等待直到警告框出现
+ WebDriverWait(driver, 10).until(EC.alert_is_present())
+
+ # 检查是否弹出警告框
+ alert = driver.switch_to.alert
+ assert "输入不能包含空格!" in alert.text
+ except (NoSuchElementException, TimeoutException) as e:
+ pytest.fail("页面元素未找到或超时: {}".format(e))
+
+
+
+# 测试重设密码页面输入新密码包含空格的情况
+
+def test_reset_password_with_space(driver, URL):
+ try:
+ driver.get(URL+"/reset")
+
+ # 输入用户名
+ username_elem = driver.find_element_by_id('username')
+ username_elem.send_keys("test_user")
+
+ # 输入包含空格的密码
+ password_elem = driver.find_element_by_id('password')
+ password_elem.send_keys("password with space")
+
+ # 提交重设密码表单
+ elem = driver.find_element_by_class_name('btn') # 找到提交按钮
+ elem.click()
+
+ # 显式等待直到警告框出现
+ WebDriverWait(driver, 10).until(EC.alert_is_present())
+
+ # 检查是否弹出警告框
+ alert = driver.switch_to.alert
+ assert "输入不能包含空格!" in alert.text
+ except (NoSuchElementException, TimeoutException) as e:
+ pytest.fail("页面元素未找到或超时: {}".format(e))
From db66b59513e894589684fdb430391343d69feec6 Mon Sep 17 00:00:00 2001
From: Sunflower613 <2963707761@qq.com>
Date: Mon, 15 Apr 2024 06:17:01 +0800
Subject: [PATCH 4/6] Fix Test Files
---
app/test/test_login_password_with_space.py | 35 ------------------
app/test/test_reset_password_with_space.py | 35 ------------------
app/test/test_signup_password_with_space.py | 39 ---------------------
3 files changed, 109 deletions(-)
delete mode 100644 app/test/test_login_password_with_space.py
delete mode 100644 app/test/test_reset_password_with_space.py
delete mode 100644 app/test/test_signup_password_with_space.py
diff --git a/app/test/test_login_password_with_space.py b/app/test/test_login_password_with_space.py
deleted file mode 100644
index 9be5118..0000000
--- a/app/test/test_login_password_with_space.py
+++ /dev/null
@@ -1,35 +0,0 @@
-from selenium import webdriver
-from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
-from selenium.webdriver.common.keys import Keys
-
-import time
-
-# 初始化WebDriver
-driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
-driver.implicitly_wait(10)
-
-
-# 测试登录页面输入密码包含空格的情况
-def test_login_password_with_space():
- try:
- driver.get("http://121.4.94.30:91/login")
-
- # 输入用户名
- username_elem = driver.find_element_by_name('username')
- username_elem.send_keys("test_user")
-
- # 输入包含空格的密码
- password_elem = driver.find_element_by_name('password')
- password_elem.send_keys("password with space")
-
- # 提交登录表单
- password_elem.send_keys(Keys.RETURN)
-
- # 等待一段时间确保页面加载完成
- time.sleep(2)
-
- # 检查是否弹出警告框
- alert = driver.switch_to.alert
- assert "输入不能包含空格!" in alert.text
- finally:
- driver.quit()
\ No newline at end of file
diff --git a/app/test/test_reset_password_with_space.py b/app/test/test_reset_password_with_space.py
deleted file mode 100644
index b2a7ac0..0000000
--- a/app/test/test_reset_password_with_space.py
+++ /dev/null
@@ -1,35 +0,0 @@
-from selenium import webdriver
-from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
-from selenium.webdriver.common.keys import Keys
-
-import time
-
-# 初始化WebDriver
-driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
-driver.implicitly_wait(10)
-
-
-# 测试重设密码页面输入旧密码或新密码包含空格的情况
-def test_reset_password_with_space():
- try:
- driver.get("http://121.4.94.30:91/reset")
-
- # 输入旧密码
- old_password_elem = driver.find_element_by_name('old_password')
- old_password_elem.send_keys("old password with space")
-
- # 输入新密码
- new_password_elem = driver.find_element_by_name('new_password')
- new_password_elem.send_keys("new password with space")
-
- # 提交重设密码表单
- new_password_elem.send_keys(Keys.RETURN)
-
- # 等待一段时间确保页面加载完成
- time.sleep(2)
-
- # 检查是否弹出警告框
- alert = driver.switch_to.alert
- assert "输入不能包含空格!" in alert.text
- finally:
- driver.quit()
diff --git a/app/test/test_signup_password_with_space.py b/app/test/test_signup_password_with_space.py
deleted file mode 100644
index 6d5f066..0000000
--- a/app/test/test_signup_password_with_space.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from selenium import webdriver
-from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
-from selenium.webdriver.common.keys import Keys
-
-import time
-
-# 初始化WebDriver
-driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
-driver.implicitly_wait(10)
-
-
-# 测试注册页面输入密码包含空格的情况
-def test_signup_password_with_space():
- try:
- driver.get("http://121.4.94.30:91/signup")
-
- # 输入用户名
- username_elem = driver.find_element_by_name('username')
- username_elem.send_keys("new_user")
-
- # 输入包含空格的密码
- password_elem = driver.find_element_by_name('password')
- password_elem.send_keys("password with space")
-
- # 再次输入密码
- password2_elem = driver.find_element_by_name('password2')
- password2_elem.send_keys("password with space")
-
- # 提交注册表单
- password2_elem.send_keys(Keys.RETURN)
-
- # 等待一段时间确保页面加载完成
- time.sleep(2)
-
- # 检查是否弹出警告框
- alert = driver.switch_to.alert
- assert "输入不能包含空格!" in alert.text
- finally:
- driver.quit()
From 1ded133056e6fa37ce6f1e6efd96816178b04c25 Mon Sep 17 00:00:00 2001
From: Sunflower613 <2963707761@qq.com>
Date: Mon, 15 Apr 2024 06:23:48 +0800
Subject: [PATCH 5/6] Fix bug 528
---
app/templates/reset.html | 4 ----
app/templates/signup.html | 4 ----
2 files changed, 8 deletions(-)
diff --git a/app/templates/reset.html b/app/templates/reset.html
index 223b902..408e001 100644
--- a/app/templates/reset.html
+++ b/app/templates/reset.html
@@ -24,10 +24,6 @@
alert('密码过于简单。(密码长度至少4位)');
return false;
}
- if (old_password.includes(' ') || new_password.includes(' ')) {
- alert('输入不能包含空格!');
- return false;
- }
$.post("/reset", {'old-password': old_password, 'new-password': new_password},
function (response) {
if (response.status === '1') {
diff --git a/app/templates/signup.html b/app/templates/signup.html
index d525154..6b5db6e 100644
--- a/app/templates/signup.html
+++ b/app/templates/signup.html
@@ -28,10 +28,6 @@ You're logged in already! Logout.
alert('密码过于简单。(密码长度至少4位)');
return false;
}
- if (password.includes(' ') || password2.includes(' ')) {
- alert('输入不能包含空格!');
- return false;
- }
$.post("/signup", {'username': username, 'password': password},
function (response) {
if (response.status === '0') {
From 739094e844d229751091f20ec29146941d0f94fe Mon Sep 17 00:00:00 2001
From: Sunflower613 <2963707761@qq.com>
Date: Mon, 22 Apr 2024 04:59:51 +0800
Subject: [PATCH 6/6] Fix Test File
---
app/test/test_bug528_tangjiao.py | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/app/test/test_bug528_tangjiao.py b/app/test/test_bug528_tangjiao.py
index c732009..802423c 100644
--- a/app/test/test_bug528_tangjiao.py
+++ b/app/test/test_bug528_tangjiao.py
@@ -6,18 +6,6 @@ from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
-# 使用 Pytest 的 fixture 初始化 WebDriver 和 URL
-@pytest.fixture(scope="module")
-def driver():
- # 初始化WebDriver
- driver = webdriver.Edge(executable_path=r'D:\codeapp\python-3.8.5\Lib\site-packages\selenium\webdriver\edge\MicrosoftWebDriver.exe')
- driver.implicitly_wait(10)
- yield driver # yield 语句之后的代码在测试用例执行完毕后运行
- driver.quit() # 测试用例执行完毕后关闭 WebDriver
-
-@pytest.fixture(scope="module")
-def URL():
- return 'http://127.0.0.1:5000'
# 测试登录页面输入密码包含空格的情况
def test_login_password_with_space(driver, URL):
@@ -44,7 +32,7 @@ def test_login_password_with_space(driver, URL):
assert "输入不能包含空格!" in alert.text
except (NoSuchElementException, TimeoutException) as e:
pytest.fail("页面元素未找到或超时: {}".format(e))
-
+
# 测试注册页面输入密码包含空格的情况