Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/config/config_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type PasscodeCharset string
var (
PasscodeCharsetNumeric PasscodeCharset = "numeric"
PasscodeCharsetAlphanumeric PasscodeCharset = "alphanumeric"
PasscodeCharsetStatic PasscodeCharset = "static"
)

func (e *Email) Validate() error {
Expand Down
13 changes: 13 additions & 0 deletions backend/crypto/passcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ func (a *alphanumericPasscodeGenerator) Generate() (string, error) {
}
return string(b), nil
}

type staticPasscodeGenerator struct {
}

func NewStaticPasscodeGenerator() PasscodeGenerator {
return &staticPasscodeGenerator{}
}

func (g *staticPasscodeGenerator) Generate() (string, error) {
// this is just a POC for now. I can imagine config option for it, or an env variable...

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.

Suggested change
// this is just a POC for now. I can imagine config option for it, or an env variable...

n := 123456
return fmt.Sprintf("%06d", n), nil
}
12 changes: 12 additions & 0 deletions backend/crypto/passcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ func TestAlphanumericPasscodeGenerator_Generate_Different_Codes(t *testing.T) {

assert.NotEqual(t, passcode1, passcode2)
}

func TestStaticPasscodeGenerator_Generate(t *testing.T) {
pg := NewStaticPasscodeGenerator()
passcode1, err := pg.Generate()

assert.NoError(t, err)
assert.NotEmpty(t, passcode1)
assert.Equal(t, 6, len(passcode1))

passcode2, err := pg.Generate()
assert.Equal(t, passcode1, passcode2)
}
2 changes: 2 additions & 0 deletions backend/flow_api/services/passcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (s *passcode) SendPasscode(tx *pop.Connection, p SendPasscodeParams) (*Send
switch p.Cfg.Email.PasscodeCharset {
case config.PasscodeCharsetAlphanumeric:
passcodeGenerator = crypto.NewAlphanumericPasscodeGenerator()
case config.PasscodeCharsetStatic:
passcodeGenerator = crypto.NewStaticPasscodeGenerator()
}
code, err := passcodeGenerator.Generate()
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions backend/json_schema/hanko.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,10 @@
"type": "string",
"enum": [
"numeric",
"alphanumeric"
"alphanumeric",
"static"
],
"description": "`passcode_charset` specifies the characters that can be used in passcodes.\nE.g. `numeric` allows only numbers, `alphanumeric` allows both numbers and letters.",
"description": "`passcode_charset` specifies the characters that can be used in passcodes.\nE.g. `numeric` allows only numbers, `alphanumeric` allows both numbers and letters, `static` returns always the same passcode 123456.\nThe `static` should be used in local test runs only.",

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.

The hanko.config.json schema is generated via schema generate config command - so comments and jsonschema tags are the source of truth. Hence we should not update this file manually because on the next generation your additions would be gone.

See this comment.

"default": "numeric"
},
"require_verification": {
Expand Down Expand Up @@ -2018,4 +2019,4 @@
}
},
"title": "Config"
}
}
Loading