Commit Graph

107 Commits

Author SHA1 Message Date
Taras Kushnir
4f8d2a9ff0 Respect context cancellation in backoff wait 2026-01-20 18:38:26 +02:00
Taras Kushnir
809a667bf9 Allow localhost subdomains 2026-01-15 14:52:54 +02:00
Taras Kushnir
0f70c38529 Add more tests
80% done by Claude Opus 4.5 w/ copilot, but not quite
2026-01-15 14:35:13 +02:00
Copilot
e09db1dbb8 Allow org members without subscription to create properties via API (#251)
* Initial plan

* Allow org members without subscription to create properties via API

- Add requestUserEx() to allow skipping subscription check
- Update postNewProperties() to not require user subscription (org owner subscription is checked instead)
- Update getAsyncTask() to not require user subscription
- Add integration tests for Portal and API to verify org members can create properties

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix TestApiPostPropertiesNoSubscription to check API error code

Update test to use requestResponseAPISuite and check for StatusSubscriptionPropertyLimitError instead of HTTP 402

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Refactor tests and fix task handler subscription check

- Fix getAsyncTask to require subscription (nil subscriptions blocked, expired trials allowed)
- Refactor API tests with helper functions createPropertyInputs, waitForAsyncTaskCompletion
- Refactor API and Portal tests as test suites for nil and expired trial subscriptions
- Add step to test non-member rejection before join in API tests
- Simplify Portal tests to focus on member property creation

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix redundant imports in property_test.go

Use consistent db_test alias instead of multiple aliases for the same package

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Add non-member rejection test and refactor async task wait helpers

- Add non-member rejection step in API tests (verifies 403 Forbidden before invite)
- Simplify Portal tests (just verify member can create properties after joining)
- Refactor multiple async task wait loops to use waitForAsyncTaskCompletion helper
- Add waitForAsyncTaskCompletionWithResult helper for tests that need results

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Ensure invited-but-not-joined members cannot create properties

- Add RetrieveUserOrganizationMember() that excludes invited users
- Add requestOrgMember() API helper that uses the new function
- Add OrgMember() Portal helper that uses the new function
- Update postNewProperties() to use requestOrgMember()
- Update postNewOrgProperty() to use OrgMember()
- Add test steps for invited-but-not-joined rejection in API and Portal tests

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Refactor: return access level from requestOrg/Org instead of new functions

- Modify RetrieveUserOrganization to return access level as third value
- Delete RetrieveUserOrganizationMember function
- Modify requestOrg to return access level as third value
- Delete requestOrgMember function
- Modify Org to return access level as third value
- Delete OrgMember function
- Update all callers to ignore unused access level return values
- Check access level in postNewProperties and postNewOrgProperty to block invited users

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix code review: use 403 Forbidden and check level.Valid

- Use HTTP 403 Forbidden instead of 500 in Portal for invited users
- Add level.Valid check before accessing level.AccessLevel

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>
2026-01-15 12:06:34 +02:00
Copilot
7d1ef63389 Add t.Helper annotations to Go test helpers (#253)
* Initial plan

* test: mark helper functions with t.Helper

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>
2026-01-14 19:20:53 +02:00
Taras Kushnir
d1c0a1afcb Split timeout handler into soft and hard
- fix potential superfluous writes like the stdlib http.TimeoutHandler
- we don't want to run extra goroutines on public unauthenticated methods
2026-01-12 12:13:02 +02:00
Taras Kushnir
3f3c0988bf Add more tests
With copilot. Merged maually due to bugs
2026-01-10 17:42:05 +02:00
Copilot
bc5f8a9d6e Add test coverage for maintenance jobs, rate limiter, cache, and portal handlers (#241)
* Initial plan

* Add unit tests for improved test coverage

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Address code review feedback

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Move integration tests to pkg/api and pkg/portal, fix TestResend2FA logic

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix code review issues: remove unused import and fix job name generation

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix TestResend2FA tests: add CSRF token and verify codes are different

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>
2026-01-08 19:56:39 +02:00
Taras Kushnir
ae0972b1d1 Fix build 2026-01-08 08:46:13 +02:00
Taras Kushnir
bb82daa529 Make global variables in tests consistent 2026-01-08 08:44:33 +02:00
Copilot
b9a3945ff0 Add negative codepath tests for API endpoints (#242)
* Initial plan

* Add negative codepath tests for API endpoints

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix task test for invalid UUID format

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

* Fix code review feedback - use t.Fatalf for consistency

Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ribtoks <505555+ribtoks@users.noreply.github.com>
2026-01-07 20:25:08 +02:00
Taras Kushnir
f534ee7ec5 Add a mode to run tests without ClickHouse 2026-01-06 15:46:24 +02:00
Taras Kushnir
8112359ef9 Add more tests 2026-01-02 18:44:17 +02:00
Taras Kushnir
acc2e09427 Add timeout config for periodic jobs 2025-12-25 13:33:19 +01:00
Taras Kushnir
cbdc994e0d Add Org scope to API keys. closes PrivateCaptcha/issues#237 2025-12-22 18:54:47 +01:00
Taras Kushnir
1478f7a376 Add read-only attribute to the scope of API key 2025-12-22 14:33:26 +01:00
Taras Kushnir
782dbb5f34 Validate API requests while reading JSON 2025-12-22 12:50:08 +01:00
Taras Kushnir
727fbfa93e Preallocate map size 2025-12-22 12:47:18 +01:00
Taras Kushnir
f308e55d91 Make properties API to use PUT 2025-12-19 20:02:27 +01:00
Taras Kushnir
f446e2884d Add API to get a single property. related PrivateCaptcha/issues#45 2025-12-18 18:17:51 +01:00
Taras Kushnir
3475c9c1e2 Add API to batch-update properties. related PrivateCaptcha/issues#45 2025-12-18 14:28:55 +01:00
Taras Kushnir
8386d16fe6 Cosmetic improvement 2025-12-18 11:02:33 +01:00
Taras Kushnir
50945a6480 Fix typo 2025-12-17 19:27:53 +01:00
Taras Kushnir
a01792ffd8 Add API to get properties. related PrivateCaptcha/issues#45 2025-12-17 19:16:18 +01:00
Taras Kushnir
66d842413a Split portal and DB page size for properties 2025-12-17 19:01:35 +01:00
Taras Kushnir
05e653631e Add pagination support for org properties. related PrivateCaptcha/issues#45 2025-12-17 18:32:41 +01:00
Taras Kushnir
653b91f86e Add API support to delete properties. related PrivateCaptcha/issues#45 2025-12-17 12:55:49 +01:00
Taras Kushnir
b959c00af8 Add create properties bulk API. related PrivateCaptcha/issues#45 2025-12-15 15:43:05 +01:00
Taras Kushnir
85ca8c5a7a Add preliminary basic version of orgs API. related PrivateCaptcha/issues#45 2025-12-10 21:15:02 +01:00
Taras Kushnir
9effd7a5df Refactor API server routes mounting 2025-12-08 17:45:52 +01:00
Taras Kushnir
57636bbf48 Add API key scope 2025-12-08 12:44:42 +01:00
Taras Kushnir
9151c22370 Cache chart stats also on the server level 2025-12-07 20:13:18 +01:00
Taras Kushnir
916bb28dd6 Add separate test for verifying test property with another sitekey 2025-12-03 16:38:22 +01:00
Taras Kushnir
58b0573a6d Add comment to flaky test 2025-12-03 11:25:33 +01:00
Taras Kushnir
008c5bea0f Fix tests 2025-12-03 11:07:13 +01:00
Taras Kushnir
cbab265d85 Send verify response instead of http code for sitekey verification 2025-12-02 21:42:01 +01:00
Taras Kushnir
1ac836c713 Fix tests 2025-12-02 20:44:47 +01:00
Taras Kushnir
c2c3fa9156 Cosmetic improvements 2025-12-02 19:55:25 +01:00
Taras Kushnir
14fa5396e5 Add more user-friendly http error body response 2025-12-02 19:21:24 +01:00
Taras Kushnir
da93cf591b Check expected sitekey in /verify 2025-12-02 18:52:43 +01:00
Taras Kushnir
fdd3d7d47b Add passthrough API headers 2025-11-27 12:10:43 +02:00
Taras Kushnir
2d67bc1875 Add more logs to sitekey endpoint for errors 2025-11-24 07:59:11 +02:00
Taras Kushnir
d8e97404d9 Tune down sitekey cached errors 2025-11-24 07:55:55 +02:00
Taras Kushnir
fa8422d1c7 Add basic auditlogs implementation. closes PrivateCaptcha/issues#204 2025-11-22 19:39:18 +02:00
Taras Kushnir
f1013af2c3 Add backpressure for org member checks 2025-11-19 14:34:18 +02:00
Taras Kushnir
884a5d2117 Force recheck user limits upon joining the org 2025-11-19 14:11:04 +02:00
Taras Kushnir
cc697aa71e Cosmetic improvement 2025-11-19 11:08:46 +02:00
Taras Kushnir
81e01d80ee Include property org members for limit checks backfill 2025-11-19 11:05:26 +02:00
Viktor Szépe
c2990f579b Correct misspellings (#217) 2025-11-19 09:40:16 +02:00
Taras Kushnir
cf374ab0e3 Add more logs for requests cut by user limiter 2025-11-19 09:33:23 +02:00