Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(api): handle branch names with slashes in them #21

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ itest:
just run_test "http://localhost:3000/v1/next.forgejo.org/cafkafk/hello.tar.gz"
just run_test "http://localhost:3000/v1/flakehub.com/cafkafk/hello/v/v0.0.1.tar.gz"

just run_test "http://localhost:3000/v1/codeberg/cafkafk/hello/b/a-/t/e/s/t/i/n/g/b/r/a/n/c/h-th@t-should-be-/ha/rd/to/d/e/a/l/wi/th.tar.gz"
just run_test "http://localhost:3000/v1/github/cafkafk/hello/b/a-/t/e/s/t/i/n/g/b/r/a/n/c/h-th@t-should-be-/ha/rd/to/d/e/a/l/wi/th.tar.gz"
just run_test "http://localhost:3000/v1/gitlab/gitlab.com/cafkafk/hello/b/a-/t/e/s/t/i/n/g/b/r/a/n/c/h-th@t-should-be-/ha/rd/to/d/e/a/l/wi/th.tar.gz"
just run_test "http://localhost:3000/v1/forgejo/next.forgejo.org/cafkafk/hello/b/a-/t/e/s/t/i/n/g/b/r/a/n/c/h-th@t-should-be-/ha/rd/to/d/e/a/l/wi/th.tar.gz"
just run_test "http://localhost:3000/v1/git.madhouse-project.org/cafkafk/hello/b/a-/t/e/s/t/i/n/g/b/r/a/n/c/h-th@t-should-be-/ha/rd/to/d/e/a/l/wi/th.tar.gz"

@echo "tests passsed :3"

# Integration Testing of rime.cx (requires Nix)
Expand All @@ -232,4 +238,6 @@ itest-live:
just run_test "http://rime.cx/v1/next.forgejo.org/cafkafk/hello.tar.gz"
just run_test "http://rime.cx/v1/flakehub.com/cafkafk/hello/v/v0.0.1.tar.gz"

just run_test "http://rime.cx/v1/git.madhouse-project.org/cafkafk/hello/b/a-/t/e/s/t/i/n/g/b/r/a/n/c/h-th@t-should-be-/ha/rd/to/d/e/a/l/wi/th.tar.gz"

@echo "tests passsed :3"
4 changes: 2 additions & 2 deletions src/api/v1/forgejo/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use axum::{routing::get, Router};

pub fn get_routes() -> Router {
Router::new()
.route("/:host/:user/:repo/b/:branch", get(get_repo_ref))
.route("/:host/:user/:repo/branch/:branch", get(get_repo_ref))
.route("/:host/:user/:repo/b/*branch", get(get_repo_ref))
.route("/:host/:user/:repo/branch/*branch", get(get_repo_ref))
.route("/:host/:user/:repo/v/:version", get(get_repo_ref))
.route("/:host/:user/:repo/version/:version", get(get_repo_ref))
.route("/:host/:user/:repo/t/:version", get(get_repo_ref))
Expand Down
4 changes: 2 additions & 2 deletions src/api/v1/github/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use axum::{routing::get, Router};

pub fn get_routes() -> Router {
Router::new()
.route("/:user/:repo/b/:branch", get(get_repo_branch))
.route("/:user/:repo/branch/:branch", get(get_repo_branch))
.route("/:user/:repo/b/*branch", get(get_repo_branch))
.route("/:user/:repo/branch/*branch", get(get_repo_branch))
.route("/:user/:repo/v/:version", get(get_repo_version))
.route("/:user/:repo/version/:version", get(get_repo_version))
.route("/:user/:repo/t/:version", get(get_repo_version))
Expand Down
3 changes: 2 additions & 1 deletion src/api/v1/gitlab/endpoints/get_repo_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ pub async fn get_repo_ref(
let git_ref_name = git_ref
.strip_suffix(".tar.gz")
.expect("couldn't strip .tar.gz suffix");
let git_ref_dashed_name = git_ref_name.replace('/', "-");
let uri = format!(
"https://{}/{}/{}/-/archive/{}/{}-{}.tar.gz",
host, user, repo, git_ref_name, repo, git_ref_name,
host, user, repo, git_ref_name, repo, git_ref_dashed_name,
);
Redirect::to(&uri).into_response()
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/api/v1/gitlab/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use axum::{routing::get, Router};

pub fn get_routes() -> Router {
Router::new()
.route("/:host/:user/:repo/b/:branch", get(get_repo_ref))
.route("/:host/:user/:repo/branch/:branch", get(get_repo_ref))
.route("/:host/:user/:repo/b/*branch", get(get_repo_ref))
.route("/:host/:user/:repo/branch/*branch", get(get_repo_ref))
.route("/:host/:user/:repo/v/:version", get(get_repo_ref))
.route("/:host/:user/:repo/version/:version", get(get_repo_ref))
.route("/:host/:user/:repo/t/:version", get(get_repo_ref))
Expand Down
4 changes: 2 additions & 2 deletions src/api/v1/sourcehut/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use super::endpoints::get_repo_ref;

pub fn get_routes() -> Router {
Router::new()
.route("/:host/:user/:repo/b/:version", get(get_repo_ref))
.route("/:host/:user/:repo/branch/:version", get(get_repo_ref))
.route("/:host/:user/:repo/b/*version", get(get_repo_ref))
.route("/:host/:user/:repo/branch/*version", get(get_repo_ref))
.route("/:host/:user/:repo/v/:version", get(get_repo_ref))
.route("/:host/:user/:repo/version/:version", get(get_repo_ref))
.route("/:host/:user/:repo/t/:version", get(get_repo_ref))
Expand Down