From 70d37c88b5cc74ab1f748956c0a81cb87a5f8a35 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 9 Aug 2023 22:38:41 +0000 Subject: [PATCH] Redo auth flow with lit. Beef up the test a bit, accordingly. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4392 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/auth.html | 103 +++++++++++++++++++++++++++++++++++++++++++++- core/auth.js | 51 +++++------------------ core/style.css | 27 ------------ tools/autotest.py | 44 +++++++++++++++++--- 4 files changed, 150 insertions(+), 75 deletions(-) diff --git a/core/auth.html b/core/auth.html index e38b2a1e..1826f381 100644 --- a/core/auth.html +++ b/core/auth.html @@ -10,10 +10,109 @@ -

Tilde Friends Sign-in

-
+ + + diff --git a/core/auth.js b/core/auth.js index 81fa51ba..d8ecac1c 100644 --- a/core/auth.js +++ b/core/auth.js @@ -121,6 +121,7 @@ function handler(request, response) { let formData = form.decodeForm(request.query); + print(request.method, utf8Decode(request.body), JSON.stringify(formData)); if (request.method == "POST" || formData.submit) { sessionIsNew = true; formData = form.decodeForm(utf8Decode(request.body), formData); @@ -178,46 +179,16 @@ function handler(request, response) { } else { File.readFile("core/auth.html").then(function(data) { let html = utf8Decode(data); - let contents = ""; - - if (entry) { - if (sessionIsNew) { - contents += '
Welcome back, ' + entry.name + '.
\n'; - } else { - contents += '
You are already logged in, ' + entry.name + '.
\n'; - } - contents += '
Logout
\n'; - } else { - contents += '
\n'; - if (loginError) { - contents += "

" + loginError + "

\n"; - } - contents += '
Halt. Who goes there?
\n' - contents += '
\n'; - contents += '
\n' - if (noAdministrator()) { - contents += '
There is currently no administrator. You will be made administrator.
\n'; - } - contents += '
\n'; - contents += '
\n'; - contents += '\n'; - contents += '
\n'; - contents += '
\n'; - contents += '
'; - contents += '
- or -
'; - contents += '
\n'; - contents += '\n'; - contents += '
\n'; - contents += '
\n'; - contents += '
\n'; - contents += '

Code of Conduct

\n'; - contents += `
\n`; - contents += '
\n'; - contents += '
'; - } - let text = html.replace("", contents); - response.writeHead(200, {"Content-Type": "text/html; charset=utf-8", "Set-Cookie": cookie, "Content-Length": text.length}); - response.end(text); + let auth_data = { + session_is_new: sessionIsNew, + name: entry?.name, + error: loginError, + code_of_conduct: core.globalSettings.code_of_conduct, + have_administrator: !noAdministrator(), + }; + html = utf8Encode(html.replace('$AUTH_DATA', JSON.stringify(auth_data))); + response.writeHead(200, {"Content-Type": "text/html; charset=utf-8", "Set-Cookie": cookie, "Content-Length": html.length}); + response.end(html); }).catch(function(error) { response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Connection": "close"}); response.end("404 File not found"); diff --git a/core/style.css b/core/style.css index 85f0251e..42e7393d 100644 --- a/core/style.css +++ b/core/style.css @@ -100,33 +100,6 @@ a:active { float: right; } -#auth_greeting { - text-align: center; -} - -#auth { - display: flex; - flex-flow: row; - align-content: center; - align-items: center; - text-align: center; - justify-content: center; -} - -#auth_login { - flex: 0 1 auto; - text-align: right; -} - -.auth_or { - flex: 0 1 auto; - padding: 1em; -} - -#auth_guest { - flex: 0 1 auto; -} - .notice { color: #cb4b16; margin: 1em; diff --git a/tools/autotest.py b/tools/autotest.py index 70e373d4..979e1df3 100644 --- a/tools/autotest.py +++ b/tools/autotest.py @@ -23,19 +23,21 @@ try: options = webdriver.FirefoxOptions() #options.add_argument('--headless') driver = webdriver.Firefox(options = options) - wait = WebDriverWait(driver, 30) + wait = WebDriverWait(driver, 10) driver.get('http://localhost:8888') driver.find_element(By.TAG_NAME, 'tf-navigation').shadow_root.find_element(By.LINK_TEXT, 'login').click() - driver.find_element(By.ID, 'register').click() - driver.find_element(By.ID, 'name').send_keys('test_user') - driver.find_element(By.ID, 'password').send_keys('test_password') - driver.find_element(By.ID, 'confirm').send_keys('test_password') - driver.find_element(By.ID, 'loginButton').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'register_label').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('test_user') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('test_password') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'confirm').send_keys('test_password') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click() + wait.until(expected_conditions.presence_of_element_located((By.ID, 'document'))) driver.switch_to.frame(driver.find_element(By.ID, 'document')) wait.until(expected_conditions.presence_of_element_located((By.LINK_TEXT, 'ssb'))).click() driver.switch_to.default_content() + wait.until(expected_conditions.presence_of_element_located((By.ID, 'content'))) driver.switch_to.frame(wait.until(expected_conditions.presence_of_element_located((By.ID, 'document')))) tf_app = wait.until(expected_conditions.presence_of_element_located((By.TAG_NAME, 'tf-app'))).shadow_root wait.until(expected_conditions.element_to_be_clickable(tf_app.find_element(By.ID, 'create_identity'))).click() @@ -48,6 +50,36 @@ try: driver.switch_to.default_content() driver.find_element(By.ID, 'allow').click() + driver.find_element(By.TAG_NAME, 'tf-navigation').shadow_root.find_element(By.LINK_TEXT, 'logout test_user').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'login_label').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('test_user') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('test_password') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click() + + wait.until(expected_conditions.presence_of_element_located((By.ID, 'content'))) + + driver.find_element(By.TAG_NAME, 'tf-navigation').shadow_root.find_element(By.LINK_TEXT, 'logout test_user').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'guest_label').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'guestButton').click() + + wait.until(expected_conditions.presence_of_element_located((By.ID, 'content'))) + driver.switch_to.frame(wait.until(expected_conditions.presence_of_element_located((By.ID, 'document')))) + wait.until(expected_conditions.presence_of_element_located((By.TAG_NAME, 'tf-app'))).shadow_root + driver.switch_to.default_content() + + driver.find_element(By.TAG_NAME, 'tf-navigation').shadow_root.find_element(By.LINK_TEXT, 'logout guest').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'login_label').click() + + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('test_user') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('wrong_password') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'error') + + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'name').send_keys('wrong_user') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'password').send_keys('test_password') + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'loginButton').click() + driver.find_element(By.TAG_NAME, 'tf-auth').shadow_root.find_element(By.ID, 'error') + print('SUCCESS.') finally: driver.close()