Skip to content

refactor(util): simplify CryptoRandomBytes parameter and improve test coverage#86

Merged
appleboy merged 4 commits intomainfrom
refactor/util-simplify-and-test
Mar 8, 2026
Merged

refactor(util): simplify CryptoRandomBytes parameter and improve test coverage#86
appleboy merged 4 commits intomainfrom
refactor/util-simplify-and-test

Conversation

@appleboy
Copy link
Copy Markdown
Member

@appleboy appleboy commented Mar 8, 2026

Summary

  • Change CryptoRandomBytes parameter type from int64 to int, removing unnecessary casts at all call sites (oauth_handler.go, sqlite.go)
  • Migrate context_test.go and url_test.go from raw t.Errorf/t.Fatal to testify assert/require for consistency with codebase convention
  • Add edge case tests: zero-length bytes, odd-length strings, empty token/salt for HashToken, invalid/unparseable URLs and non-http schemes for IsRedirectSafe
  • Test coverage for internal/util/ improved from 92.3% to 97.4%

Test plan

  • go build ./... compiles successfully
  • go test ./internal/util/ -v — all tests pass
  • Coverage verified: IsRedirectSafe 90.9% → 100%, overall 92.3% → 97.4%

🤖 Generated with Claude Code

… coverage

- Change CryptoRandomBytes parameter type from int64 to int, removing unnecessary casts at call sites
- Migrate context_test.go and url_test.go to use testify assertions for consistency
- Add edge case tests for zero length, odd length, empty token/salt, and invalid URLs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 8, 2026 04:22
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors internal/util.CryptoRandomBytes to accept an int length (aligning with Go slice sizing) and expands/standardizes internal/util tests (testify assert/require) to improve coverage around crypto helpers and redirect URL safety.

Changes:

  • Change CryptoRandomBytes signature from int64int and update call sites.
  • Migrate util tests to testify assert/require style for consistency.
  • Add edge-case tests for crypto helpers and IsRedirectSafe (including invalid URLs and non-http schemes).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/util/crypto.go Simplifies CryptoRandomBytes signature and removes unnecessary casts in util crypto helpers.
internal/store/sqlite.go Updates password generation to use new CryptoRandomBytes(int) signature.
internal/handlers/oauth_handler.go Updates OAuth state generation to use new CryptoRandomBytes(int) signature.
internal/util/crypto_test.go Adds edge-case coverage for random bytes/strings and HashToken.
internal/util/context_test.go Converts tests to testify assertions for consistency.
internal/util/url_test.go Adds redirect safety edge cases and converts to testify assertions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

appleboy and others added 3 commits March 8, 2026 12:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@appleboy appleboy merged commit 4c7238a into main Mar 8, 2026
2 checks passed
@appleboy appleboy deleted the refactor/util-simplify-and-test branch March 8, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants