From c516ce206080960cf8d621eeff774dc38ec043e8 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 09:29:33 +0300 Subject: [PATCH 01/12] hotfix login --- src/user_routes.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_routes.v b/src/user_routes.v index 3bffdd6b..4c5e825d 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -11,7 +11,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { csrf := rand.string(30) ctx.set_cookie(name: 'csrf', value: csrf) - if app.is_logged_in(mut ctx) { + if !app.is_logged_in(mut ctx) { return ctx.not_found() } From 6818b7fb25d6ad333e8ce95241503975c658a043 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 11:51:07 +0300 Subject: [PATCH 02/12] main: Add veb.Middleware to App;make use of app.before_request --- src/gitly.v | 1 + src/main.v | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/gitly.v b/src/gitly.v index ece88086..214d97c3 100644 --- a/src/gitly.v +++ b/src/gitly.v @@ -23,6 +23,7 @@ const namechange_period = time.hour * 24 @[heap] pub struct App { veb.StaticHandler + veb.Middleware[Context] started_at i64 pub mut: db sqlite.DB diff --git a/src/main.v b/src/main.v index f38b405c..5af48d6e 100644 --- a/src/main.v +++ b/src/main.v @@ -12,6 +12,8 @@ fn main() { return } mut app := new_app()! + + app.use(handler: app.before_request) // vweb.run_at(new_app()!, http_port) veb.run_at[App, Context](mut app, port: http_port, family: .ip, timeout_in_seconds: 2) or { From bd260777c59e01a7c9495d4e20ef73000c3d9220 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 14:11:39 +0300 Subject: [PATCH 03/12] login: get logic back --- src/user_routes.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_routes.v b/src/user_routes.v index 4c5e825d..3bffdd6b 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -11,7 +11,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { csrf := rand.string(30) ctx.set_cookie(name: 'csrf', value: csrf) - if !app.is_logged_in(mut ctx) { + if app.is_logged_in(mut ctx) { return ctx.not_found() } From 8a0bbf4b941114a7f9fde0bca9ac614f417407bc Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 16:46:59 +0300 Subject: [PATCH 04/12] app: hotfix request timeout, add url var and dump it (don't ask me) --- src/gitly.v | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gitly.v b/src/gitly.v index 214d97c3..02391037 100644 --- a/src/gitly.v +++ b/src/gitly.v @@ -132,6 +132,7 @@ pub fn (mut app App) init_server() { } pub fn (mut app App) before_request(mut ctx Context) { + url := ctx.req.url ctx.logged_in = app.is_logged_in(mut ctx) app.load_settings() @@ -142,6 +143,7 @@ pub fn (mut app App) before_request(mut ctx Context) { User{} } } + dump(url) } @['/'] From 1d4f83197b0a3d3372f2ba594461159660e701e5 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Fri, 21 Mar 2025 17:25:41 +0300 Subject: [PATCH 05/12] fix logic if logged in --- src/user_routes.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user_routes.v b/src/user_routes.v index 3bffdd6b..61179a50 100644 --- a/src/user_routes.v +++ b/src/user_routes.v @@ -12,7 +12,7 @@ pub fn (mut app App) login(mut ctx Context) veb.Result { ctx.set_cookie(name: 'csrf', value: csrf) if app.is_logged_in(mut ctx) { - return ctx.not_found() + return ctx.redirect("/" + ctx.user.username) } return $veb.html() From dcc76dfdea2b963ed084820d4bac169fd72c2838 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 08:05:10 +0300 Subject: [PATCH 06/12] add repo page test; increase wait timeout to make it work locally --- tests/first_run.v | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/first_run.v b/tests/first_run.v index 2169d04d..2d88f144 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -41,16 +41,18 @@ fn main() { assert get_repo_issue_count(token, test_username, 'test1') == 0 assert get_repo_branch_count(token, test_username, 'test1') == 0 - test_create_repo(token, 'test2', test_github_repo_url) + repo_name := 'test2' + test_create_repo(token, repo_name, test_github_repo_url) // wait while repo is cloning - time.sleep(3 * time.second) + time.sleep(5 * time.second) // get repo - assert get_repo_commit_count(token, test_username, 'test2', test_github_repo_primary_branch) > 0 - assert get_repo_issue_count(token, test_username, 'test2') == 0 - assert get_repo_branch_count(token, test_username, 'test2') > 0 + assert get_repo_commit_count(token, test_username, repo_name, test_github_repo_primary_branch) > 0 + assert get_repo_issue_count(token, test_username, repo_name) == 0 + assert get_repo_branch_count(token, test_username, repo_name) > 0 + test_repo_page(test_username, repo_name) ilog("all tests passed!") - after()! + // after()! } fn before() ! { @@ -188,6 +190,13 @@ fn test_user_page(username string) { assert user_page_result.body.contains('

${username}

') } +fn test_repo_page(username string, repo_name string) { + ilog('Testing the new repo /${username}/${repo_name} page is up') + repo_page_result := http.get(prepare_url("${username}/${repo_name}")) or { exit_with_message(err.str()) } + + assert repo_page_result.status_code == 200 +} + fn test_login_with_token(username string, token string) { ilog('Try to login in with `${username}` user token') From 6b8c7293439d944637e640a80ba4c426da6692ee Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 08:06:37 +0300 Subject: [PATCH 07/12] uncomment after() --- tests/first_run.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/first_run.v b/tests/first_run.v index 2d88f144..c284e64d 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -52,7 +52,7 @@ fn main() { test_repo_page(test_username, repo_name) ilog("all tests passed!") - // after()! + after()! } fn before() ! { From 934745403004bc1f1347cb36914a74b220f7fe6b Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 08:16:36 +0300 Subject: [PATCH 08/12] test repos and branch pages --- tests/first_run.v | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/first_run.v b/tests/first_run.v index c284e64d..6c95924c 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -50,6 +50,8 @@ fn main() { assert get_repo_issue_count(token, test_username, repo_name) == 0 assert get_repo_branch_count(token, test_username, repo_name) > 0 test_repo_page(test_username, repo_name) + test_branch_page(test_username, repo_name, test_github_repo_primary_branch) + test_repos_page(test_username) ilog("all tests passed!") after()! @@ -197,6 +199,20 @@ fn test_repo_page(username string, repo_name string) { assert repo_page_result.status_code == 200 } +fn test_branch_page(username string, repo_name string, branch_name string) { + ilog('Testing the new branch /${username}/${repo_name}/tree/${branch_name} page is up') + branch_page_result := http.get(prepare_url("${username}/${repo_name}/tree/${branch_name}")) or { exit_with_message(err.str()) } + + assert branch_page_result.status_code == 200 +} + +fn test_repos_page(username string) { + ilog('Testing the new repos /${username}/repos page is up') + repos_page_result := http.get(prepare_url("${username}/repos")) or { exit_with_message(err.str()) } + + assert repos_page_result.status_code == 200 +} + fn test_login_with_token(username string, token string) { ilog('Try to login in with `${username}` user token') From 422b5e1ab4b595430d5fa2fda2e64012603a00d5 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 08:31:26 +0300 Subject: [PATCH 09/12] define general fn test_endpoint_page; test repo settings page --- tests/first_run.v | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/first_run.v b/tests/first_run.v index 6c95924c..9dcd40ff 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -52,6 +52,7 @@ fn main() { test_repo_page(test_username, repo_name) test_branch_page(test_username, repo_name, test_github_repo_primary_branch) test_repos_page(test_username) + test_repo_settings_page(test_username, repo_name) ilog("all tests passed!") after()! @@ -213,6 +214,17 @@ fn test_repos_page(username string) { assert repos_page_result.status_code == 200 } +fn test_repo_settings_page(username string, repo_name string) { + test_endpoint_page("${username}/${repo_name}/settings", 'settings') +} + +fn test_endpoint_page(endpoint string, pagename string) { + ilog('Testing the new ${pagename} /${endpoint} page is up') + endpoint_result := http.get(prepare_url("${endpoint}")) or { exit_with_message(err.str()) } + + assert endpoint_result.status_code == 200 +} + fn test_login_with_token(username string, token string) { ilog('Try to login in with `${username}` user token') From 7ce3251b617c599e35791bebeba8c121612e0d43 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 08:42:35 +0300 Subject: [PATCH 10/12] test contributors, stars, settings pages --- tests/first_run.v | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/first_run.v b/tests/first_run.v index 9dcd40ff..b3da902c 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -53,6 +53,10 @@ fn main() { test_branch_page(test_username, repo_name, test_github_repo_primary_branch) test_repos_page(test_username) test_repo_settings_page(test_username, repo_name) + test_contributors_page(test_username, repo_name) + // test_issues_page(test_username) + test_stars_page(test_username) + test_settings_page(test_username) ilog("all tests passed!") after()! @@ -214,6 +218,31 @@ fn test_repos_page(username string) { assert repos_page_result.status_code == 200 } +fn test_contributors_page(username string, repo_name string) { + ilog('Testing the new contributors /${username}/${repo_name}/contributors page is up') + contributors_page_result := http.get(prepare_url("${username}/${repo_name}/contributors")) or { exit_with_message(err.str()) } + + assert contributors_page_result.status_code == 200 +} + +// fn test_issues_page(username string) { +// test_endpoint_page("${username}/issues", 'issues') +// } + +fn test_stars_page(username string) { + ilog("Testing the new stars /${username}/stars page is up") + stars_page_result := http.get(prepare_url("${username}/stars")) or { exit_with_message(err.str()) } + + assert stars_page_result.status_code == 200 +} + +fn test_settings_page(username string) { + ilog('Testing the new settings /${username}/settings page is up') + settings_page_result := http.get(prepare_url("${username}/settings")) or { exit_with_message(err.str()) } + + assert settings_page_result.status_code == 200 +} + fn test_repo_settings_page(username string, repo_name string) { test_endpoint_page("${username}/${repo_name}/settings", 'settings') } From 2bac962d49be1e0248e744517db524a09a679fa5 Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 09:03:15 +0300 Subject: [PATCH 11/12] test commits, branches pages --- tests/first_run.v | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/first_run.v b/tests/first_run.v index b3da902c..d7007691 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -57,6 +57,9 @@ fn main() { // test_issues_page(test_username) test_stars_page(test_username) test_settings_page(test_username) + test_commits_page(test_username, repo_name, test_github_repo_primary_branch) + test_branches_page(test_username, repo_name) + // test_api_branches_count(test_username, repo_name) ilog("all tests passed!") after()! @@ -225,6 +228,37 @@ fn test_contributors_page(username string, repo_name string) { assert contributors_page_result.status_code == 200 } +fn test_commits_page(username string, repo_name string, branch_name string) { + ilog('Testing the new commits /${username}/${repo_name}/${branch_name}/commits/1 page is up') + // Doesn't work with commits/[no 1] + commits_page_result := http.get(prepare_url("${username}/${repo_name}/${branch_name}/commits/1")) or { exit_with_message(err.str()) } + + assert commits_page_result.status_code == 200 +} + +fn test_branches_page(username string, repo_name string) { + ilog('Testing the new branches /${username}/${repo_name}/branches page is up') + branches_page_result := http.get(prepare_url("${username}/${repo_name}/branches")) or { exit_with_message(err.str()) } + + assert branches_page_result.status_code == 200 +} + +fn test_api_branches_count(username string, repo_name string) { + ilog('Testing if api/v1/${username}/${repo_name}/branches/count works') + api_branches_count_result := http.get(prepare_url("api/v1/${username}/${repo_name}/branches/count")) or { exit_with_message(err.str()) } + // api_branches_count_result := http.fetch( + // method: .get + // url: prepare_url("api/v1/${username}/${repo_name}/branches/count") + // ) or { exit_with_message(err.str()) } + + assert api_branches_count_result.status_code == 200 + + response_json := json.decode(api.ApiBranchCount, api_branches_count_result.body) or { + exit_with_message(err.str()) + } + assert response_json.result > 0 +} + // fn test_issues_page(username string) { // test_endpoint_page("${username}/issues", 'issues') // } From 0e0218e1c06b7b3bdaf6a42de7eba2e30085146d Mon Sep 17 00:00:00 2001 From: Paul Stern Date: Tue, 25 Mar 2025 09:23:28 +0300 Subject: [PATCH 12/12] test oauth, repo tree pages --- tests/first_run.v | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/first_run.v b/tests/first_run.v index d7007691..833fada5 100644 --- a/tests/first_run.v +++ b/tests/first_run.v @@ -35,6 +35,7 @@ fn main() { test_user_page(test_username) test_login_with_token(test_username, token) test_static_served() + test_oauth_page() test_create_repo(token, 'test1', '') assert get_repo_commit_count(token, test_username, 'test1', default_branch) == 0 @@ -59,6 +60,8 @@ fn main() { test_settings_page(test_username) test_commits_page(test_username, repo_name, test_github_repo_primary_branch) test_branches_page(test_username, repo_name) + test_repo_tree(test_username, repo_name, test_github_repo_primary_branch, 'c') + // test_refs_page(test_username, repo_name) // test_api_branches_count(test_username, repo_name) ilog("all tests passed!") @@ -259,6 +262,26 @@ fn test_api_branches_count(username string, repo_name string) { assert response_json.result > 0 } +fn test_refs_page(username string, repo_name string) { + ilog('Testing the new refs /${username}/${repo_name}/info/refs page is up') + refs_page_result := http.get(prepare_url("${username}/${repo_name}/info/refs")) or { exit_with_message(err.str()) } + + assert refs_page_result.status_code == 200 +} + +fn test_oauth_page() { + ilog('Testing the new oauth /oauth page is up') + oauth_page_result := http.get(prepare_url("oauth")) or { exit_with_message(err.str()) } + + assert oauth_page_result.status_code == 200 +} + +fn test_repo_tree(username string, repo_name string, branch_name string, path string) { + ilog('Testing the new tree /${username}/${repo_name}/tree/${branch_name}/${path} page is up') + repo_tree_result := http.get(prepare_url("${username}/${repo_name}/tree/${branch_name}/${path}")) or { exit_with_message(err.str()) } + + assert repo_tree_result.status_code == 200 +} // fn test_issues_page(username string) { // test_endpoint_page("${username}/issues", 'issues') // }