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

fix: magiclink failing due to passwordStrength check #1769

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

klajdi369
Copy link

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

#1761

What is the new behavior?

Now the password should generate secure enough with the necessary password requirements specified in environment variables.

Additional context

Basically this line in /internal/api/magic_link.go
password.Generate(64, 10, 1, false, true)
Generates an invalid value for this line in /internal/api/signup.go
if err := a.checkPasswordStrength(ctx, p.Password); err != nil {

@klajdi369 klajdi369 requested a review from a team as a code owner September 6, 2024 20:47
@klajdi369 klajdi369 changed the title Fix-magiclink-requiredchars fix: magiclink failing due to passwordStrength check Sep 9, 2024
@klajdi369 klajdi369 marked this pull request as draft September 10, 2024 20:18
@klajdi369 klajdi369 marked this pull request as ready for review September 10, 2024 20:50
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10800290811

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 32 of 46 (69.57%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 57.958%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/api/magic_link.go 1 3 33.33%
internal/utilities/password.go 31 43 72.09%
Totals Coverage Status
Change from base Build 10779572699: 0.04%
Covered Lines: 9169
Relevant Lines: 15820

💛 - Coveralls

Comment on lines +9 to +17
// parseGroups processes the required character groups from a slice of strings.
func parseGroups(requiredChars []string) []string {
var groups []string
groups = append(groups, requiredChars...)
return groups
}

func GeneratePassword(requiredChars []string, length int) (string, error) {
groups := parseGroups(requiredChars)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can reference the parameter directly since we don't mutate the slice.

Suggested change
// parseGroups processes the required character groups from a slice of strings.
func parseGroups(requiredChars []string) []string {
var groups []string
groups = append(groups, requiredChars...)
return groups
}
func GeneratePassword(requiredChars []string, length int) (string, error) {
groups := parseGroups(requiredChars)
func GeneratePassword(requiredChars []string, length int) (string, error) {

passwordBuilder.Grow(length)

// Add required characters
for _, group := range groups {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for _, group := range groups {
for _, group := range requiredChars {

}

// Define a default character set for random generation (if needed)
allChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
allChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
const allChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Copy link
Contributor

Choose a reason for hiding this comment

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

If we can move this into internal/crypto/password.go I think the change will look good to me. A unit test would be a nice addition if time permits.

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.

3 participants