-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): Allow configurable login expiration.
Login JWT tokens can now have configurable expiration. It will default to 7 days; but the staging and production environments will have theirs increased to 14 days. Resolves #1263
- Loading branch information
1 parent
bacf437
commit 81f4ab6
Showing
8 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/monetr/monetr/pkg/config" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadConfiguration(t *testing.T) { | ||
t.Run("login expiration default values", func(t *testing.T) { | ||
v := viper.GetViper() | ||
// Don't set a value for login expiration at all. | ||
|
||
configuration := config.LoadConfigurationEx(v) | ||
assert.NotZero(t, configuration.JWT.LoginExpiration, "Login expiration should not be zero") | ||
assert.EqualValues(t, 7, configuration.JWT.LoginExpiration, "Login expiration should be 7 days by default") | ||
}) | ||
|
||
t.Run("login expiration non-default values", func(t *testing.T) { | ||
v := viper.GetViper() | ||
durationString := "30" | ||
v.Set("jwt.loginExpiration", durationString) | ||
|
||
configuration := config.LoadConfigurationEx(v) | ||
assert.NotZero(t, configuration.JWT.LoginExpiration, "Login expiration should not be zero") | ||
assert.EqualValues(t, 30, configuration.JWT.LoginExpiration, "when specified, the login expiration should not be the default") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters