Skip to content

refactor(api): deduplicate HTTP test helpers and allow session cookie access - #9977

Merged
acolomb merged 3 commits into
syncthing:mainfrom
emlun:api-test-http-helpers-from-webauthn
Mar 7, 2025
Merged

acolomb merged 3 commits into
syncthing:mainfrom
emlun:api-test-http-helpers-from-webauthn

Conversation

@emlun

@emlun emlun commented Mar 1, 2025

Copy link
Copy Markdown
Member

These refactorizations were made in PR #9175 to accommodate a few new variants of authentication method and body content. On request from reviewers, this PR extracts it as a smaller refactorization to review in isolation.

Purpose

This extracts a shared httpRequest base function from httpGet and httpPost, which will be used in PR #9175 for new helper functions httpGetCsrf (hiding all optional parameters except the CSRF token), httpPostCsrf (same) and httpPostCsrfAuth (hiding basic auth parameters). A getSessionCookie function is also extracted from hasSessionCookie and will be used to test that concurrent WebAuthn authentications result in separate sessions (indicated by different session cookies).

Testing

Tests still pass after the change.

These refactorizations were made in [PR syncthing#9175][1] to accommodate a few new
variants of authentication method and body content. On request from reviewers,
this PR extracts it as a smaller refactorization to review in isolation.

This extracts a shared `httpRequest` base function from `httpGet` and
`httpPost`, which will be used in PR syncthing#9175 for new helper functions
`httpGetCsrf` (hiding all optional parameters except the CSRF token),
`httpPostCsrf` (same) and `httpPostCsrfAuth` (hiding basic auth parameters). A
`getSessionCookie` function is also extracted from `hasSessionCookie` and will
be used to test that concurrent WebAuthn authentications result in separate
sessions (indicated by different session cookies).

[1]: syncthing#9175

@acolomb acolomb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable and it touches only the test file, which still passes fine. So I'm inclined to get this done with quickly. However, leaving a chance for a second opinion.

@acolomb acolomb changed the title Extract HTTP test helper refactoring from WebAuthn PR chore(api): refactor HTTP test helpers Mar 2, 2025
@acolomb acolomb changed the title chore(api): refactor HTTP test helpers refactor(api): deduplicate HTTP test helpers and allow session cookie access Mar 2, 2025
@emlun

emlun commented Mar 6, 2025

Copy link
Copy Markdown
Member Author

@acolomb Is this okay to merge or should I continue to wait for a second opinion?

@acolomb
acolomb merged commit 8461ca5 into syncthing:main Mar 7, 2025
@acolomb

acolomb commented Mar 7, 2025

Copy link
Copy Markdown
Member

Any objections would have been raised by now... Sorry for the wait, I'm a bit busy right now and for the next few days.

@emlun
emlun deleted the api-test-http-helpers-from-webauthn branch March 7, 2025 10:14
@emlun

emlun commented Mar 7, 2025

Copy link
Copy Markdown
Member Author

No worries at all! I'm not exactly in a position to complain about things taking time 😅

calmh added a commit to calmh/syncthing that referenced this pull request Mar 8, 2025
* main:
  refactor(api): make shutdown timeout configurable for tests (syncthing#9980)
  refactor(api): deduplicate HTTP test helpers and allow session cookie access (syncthing#9977)
  build: correct API call for Weblate statistics
@calmh calmh added this to the v1.29.3 milestone Mar 9, 2025
calmh added a commit that referenced this pull request Mar 10, 2025
* main: (25 commits)
  refactor(api): make shutdown timeout configurable for tests (#9980)
  refactor(api): deduplicate HTTP test helpers and allow session cookie access (#9977)
  build: correct API call for Weblate statistics
  build(deps): update dependencies (#9978)
  chore(etc): remove /usr/bin prefix from Linux .desktop files (#9966)
  build: use Go 1.24, minimum is Go 1.23 (#9960)
  fix(policy): do not require multiple maintainers for build changes
  chore(gui, man, authors): update docs, translations, and contributors
  chore(fs): build kqueue instead of fsevents watcher on iOS (#9950)
  build(deps): update dependencies (#9951)
  refactor: using slices.Contains to simplify the code (#9918)
  build: switch to cloud code signing for Windows (#9948)
  chore(gui, man, authors): update docs, translations, and contributors
  chore(gui, man, authors): update docs, translations, and contributors
  fix(model): clarify errors on Windows user/group lookup (fixes #9929) (#9930)
  chore(gui, man, authors): update docs, translations, and contributors
  chore(scanner): don't warn about cancelled scan (#9920)
  chore(gui, man, authors): update docs, translations, and contributors
  chore(proto): change symlinktarget to be byte sequence (fixes #9913) (#9914)
  fix(api): don't crash requests after failing to unmarshal tokens (fixes #9909) (#9912)
  ...
calmh added a commit to p0l0us/syncthing that referenced this pull request Mar 28, 2025
* main: (175 commits)
  build: move nightly build schedule to separate workflow (syncthing#10000)
  chore(syncthing): use file lock on certificate to prevent multiple instances (syncthing#10003)
  chore(ur): add RSS to reported stats (syncthing#10002)
  chore(gui, man, authors): update docs, translations, and contributors
  chore(gui, man, authors): update docs, translations, and contributors
  fix(api): prevent tilde expansion in path suggestions (fixes syncthing#9990) (syncthing#9992)
  fix(syncthing): don't auto upgrade to higher major on startup (syncthing#9989)
  build(deps): update dependencies (syncthing#9988)
  chore(gui, man, authors): update docs, translations, and contributors
  refactor(api): extract method configMuxBuilder.postAdjustGui and add test coverage (syncthing#9979)
  refactor(api): make shutdown timeout configurable for tests (syncthing#9980)
  refactor(api): deduplicate HTTP test helpers and allow session cookie access (syncthing#9977)
  build: correct API call for Weblate statistics
  build(deps): update dependencies (syncthing#9978)
  chore(etc): remove /usr/bin prefix from Linux .desktop files (syncthing#9966)
  build: use Go 1.24, minimum is Go 1.23 (syncthing#9960)
  fix(policy): do not require multiple maintainers for build changes
  chore(gui, man, authors): update docs, translations, and contributors
  chore(fs): build kqueue instead of fsevents watcher on iOS (syncthing#9950)
  build(deps): update dependencies (syncthing#9951)
  ...
calmh added a commit to tomasz1986/syncthing that referenced this pull request Mar 28, 2025
…-is-disabled-for-Send-Only-folders

* main: (266 commits)
  build: move nightly build schedule to separate workflow (syncthing#10000)
  chore(syncthing): use file lock on certificate to prevent multiple instances (syncthing#10003)
  chore(ur): add RSS to reported stats (syncthing#10002)
  chore(gui, man, authors): update docs, translations, and contributors
  chore(gui, man, authors): update docs, translations, and contributors
  fix(api): prevent tilde expansion in path suggestions (fixes syncthing#9990) (syncthing#9992)
  fix(syncthing): don't auto upgrade to higher major on startup (syncthing#9989)
  build(deps): update dependencies (syncthing#9988)
  chore(gui, man, authors): update docs, translations, and contributors
  refactor(api): extract method configMuxBuilder.postAdjustGui and add test coverage (syncthing#9979)
  refactor(api): make shutdown timeout configurable for tests (syncthing#9980)
  refactor(api): deduplicate HTTP test helpers and allow session cookie access (syncthing#9977)
  build: correct API call for Weblate statistics
  build(deps): update dependencies (syncthing#9978)
  chore(etc): remove /usr/bin prefix from Linux .desktop files (syncthing#9966)
  build: use Go 1.24, minimum is Go 1.23 (syncthing#9960)
  fix(policy): do not require multiple maintainers for build changes
  chore(gui, man, authors): update docs, translations, and contributors
  chore(fs): build kqueue instead of fsevents watcher on iOS (syncthing#9950)
  build(deps): update dependencies (syncthing#9951)
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jul 1, 2026
@syncthing syncthing locked and limited conversation to collaborators Jul 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants