Skip to content

Commit

Permalink
fix(forgejo): Revert "Improved auto-detection"
Browse files Browse the repository at this point in the history
This reverts commit 41c5ec9, because
the auto-detection done in it turned out to be unreliable. The old
method might be a tiny bit more expensive, not as nice, but it is
reliable, because it does not depend on the Forgejo instance
configuration.

Also re-enable the tests that were failing due to the naive
auto-detection breaking because the cookie name was changed server-side.

Fixes #91.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
  • Loading branch information
algernon authored and cafkafk committed Mar 4, 2024
1 parent 434bc7a commit 9baed8d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 117 deletions.
108 changes: 1 addition & 107 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hyper = { version = "1.1.0", features = ["client"] }
log = "0.4.20"
pretty_env_logger = "0.5.0"
regex = "1.10.2"
reqwest = { version = "0.11.24", features = ["cookies", "json"] }
reqwest = { version = "0.11.24", features = ["json"] }
semver = "1.0.22"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.113"
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ itest:
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/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"
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"

# Test semantic versioning
just run_test "http://localhost:3000/v1/github/cafkafk/hello/s/*.tar.gz"
Expand Down Expand Up @@ -298,7 +298,7 @@ itest-live:
just run_test "http://rime.cx/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://rime.cx/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://rime.cx/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://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"
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"

# Test semantic versioning
just run_test "http://rime.cx/v1/github/cafkafk/hello/s/*.tar.gz"
Expand Down
14 changes: 7 additions & 7 deletions src/api/v1/forges/forgejo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ impl Forgejo {
}

pub async fn is_host_forgejo(host: &str) -> Result<bool, ForgeError> {
let uri = format!("https://{}/swagger.v1.json", &host);
let client = reqwest::Client::builder()
.user_agent(USER_AGENT)
.cookie_store(true)
.build()?;
// I couldn't find a more reasonable way to detect Forgejo, so we'll check
// an API endpoint that is specific to this forge, and if it exists, we
// assume it's a Forgejo instance.
let uri = format!("https://{}/api/v1/settings/api", &host);
let client = reqwest::Client::builder().user_agent(USER_AGENT).build()?;
let res = client
.head(uri)
.get(&uri)
.header(ACCEPT, "application/json")
.send()
.await?;
Ok(res.status() == 200 && res.cookies().any(|cookie| cookie.name() == "i_like_gitea"))
Ok(res.status() == 200)
}
}

Expand Down

0 comments on commit 9baed8d

Please sign in to comment.