Skip to content

Commit 6b03573

Browse files
committed
fix
1 parent e94723f commit 6b03573

File tree

20 files changed

+149
-167
lines changed

20 files changed

+149
-167
lines changed

cmd/generate.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
Usage: "Generate a secret token",
3030
Subcommands: []*cli.Command{
3131
microcmdGenerateInternalToken,
32-
microcmdGenerateLfsJwtSecret,
32+
microcmdGenerateGeneralWebSecret,
3333
microcmdGenerateSecretKey,
3434
},
3535
}
@@ -40,18 +40,17 @@ var (
4040
Action: runGenerateInternalToken,
4141
}
4242

43-
microcmdGenerateLfsJwtSecret = &cli.Command{
44-
Name: "JWT_SECRET",
45-
Aliases: []string{"LFS_JWT_SECRET"},
46-
Usage: "Generate a new JWT_SECRET",
47-
Action: runGenerateLfsJwtSecret,
48-
}
49-
5043
microcmdGenerateSecretKey = &cli.Command{
5144
Name: "SECRET_KEY",
5245
Usage: "Generate a new SECRET_KEY",
5346
Action: runGenerateSecretKey,
5447
}
48+
49+
microcmdGenerateGeneralWebSecret = &cli.Command{
50+
Name: "GENERAL_WEB_SECRET",
51+
Usage: "Generate a new GENERAL_WEB_SECRET",
52+
Action: runGenerateGeneralWebSecret,
53+
}
5554
)
5655

5756
func runGenerateInternalToken(c *cli.Context) error {
@@ -69,18 +68,15 @@ func runGenerateInternalToken(c *cli.Context) error {
6968
return nil
7069
}
7170

72-
func runGenerateLfsJwtSecret(c *cli.Context) error {
73-
_, jwtSecretBase64, err := generate.NewJwtSecretWithBase64()
71+
func runGenerateGeneralWebSecret(c *cli.Context) error {
72+
_, webSecretBase64, err := generate.NewGeneralWebSecretWithBase64()
7473
if err != nil {
7574
return err
7675
}
77-
78-
fmt.Printf("%s", jwtSecretBase64)
79-
76+
fmt.Printf("%s", webSecretBase64)
8077
if isatty.IsTerminal(os.Stdout.Fd()) {
8178
fmt.Printf("\n")
8279
}
83-
8480
return nil
8581
}
8682

cmd/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func runServ(c *cli.Context) error {
277277
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
278278

279279
// Sign and get the complete encoded token as a string using the secret
280-
tokenString, err := token.SignedString(setting.LFS.JWTSecretBytes)
280+
tokenString, err := token.SignedString(setting.GetGeneralTokenSigningSecret())
281281
if err != nil {
282282
return fail(ctx, "Failed to sign JWT Token", "Failed to sign JWT token: %v", err)
283283
}

custom/conf/app.example.ini

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,6 @@ RUN_USER = ; git
302302
;; Enables git-lfs support. true or false, default is false.
303303
;LFS_START_SERVER = false
304304
;;
305-
;;
306-
;; LFS authentication secret, change this yourself
307-
;LFS_JWT_SECRET =
308-
;;
309-
;; Alternative location to specify LFS authentication secret. You cannot specify both this and LFS_JWT_SECRET, and must pick one
310-
;LFS_JWT_SECRET_URI = file:/etc/gitea/lfs_jwt_secret
311-
;;
312305
;; LFS authentication validity period (in time.Duration), pushes taking longer than this may fail.
313306
;LFS_HTTP_AUTH_EXPIRY = 24h
314307
;;
@@ -428,18 +421,24 @@ INSTALL_LOCK = false
428421
;;
429422
;; Global secret key that will be used
430423
;; This key is VERY IMPORTANT. If you lose it, the data encrypted by it (like 2FA secret) can't be decrypted anymore.
431-
SECRET_KEY =
424+
;SECRET_KEY =
432425
;;
433426
;; Alternative location to specify secret key, instead of this file; you cannot specify both this and SECRET_KEY, and must pick one
434427
;; This key is VERY IMPORTANT. If you lose it, the data encrypted by it (like 2FA secret) can't be decrypted anymore.
435428
;SECRET_KEY_URI = file:/etc/gitea/secret_key
436429
;;
437430
;; Secret used to validate communication within Gitea binary.
438-
INTERNAL_TOKEN =
431+
;INTERNAL_TOKEN =
439432
;;
440433
;; Alternative location to specify internal token, instead of this file; you cannot specify both this and INTERNAL_TOKEN, and must pick one
441434
;INTERNAL_TOKEN_URI = file:/etc/gitea/internal_token
442435
;;
436+
;; A general secret used for signing or encrypting web related contents (CSRF token, JWT token, validation, etc)
437+
;GENERAL_WEB_SECRET =
438+
;;
439+
;; Alternative location to specify general web secret (eg: file:/etc/gitea/general_web_secret), you cannot specify both this and GENERAL_WEB_SECRET, and must pick one
440+
;GENERAL_WEB_SECRET_URI =
441+
;;
443442
;; How long to remember that a user is logged in before requiring relogin (in days)
444443
;LOGIN_REMEMBER_DAYS = 31
445444
;;
@@ -538,13 +537,6 @@ ENABLED = true
538537
;; The file must contain a RSA or ECDSA private key in the PKCS8 format. If no key exists a 4096 bit key will be created for you.
539538
;JWT_SIGNING_PRIVATE_KEY_FILE = jwt/private.pem
540539
;;
541-
;; OAuth2 authentication secret for access and refresh tokens, change this yourself to a unique string. CLI generate option is helpful in this case. https://docs.gitea.io/en-us/command-line/#generate
542-
;; This setting is only needed if JWT_SIGNING_ALGORITHM is set to HS256, HS384 or HS512.
543-
;JWT_SECRET =
544-
;;
545-
;; Alternative location to specify OAuth2 authentication secret. You cannot specify both this and JWT_SECRET, and must pick one
546-
;JWT_SECRET_URI = file:/etc/gitea/oauth2_jwt_secret
547-
;;
548540
;; Lifetime of an OAuth2 access token in seconds
549541
;ACCESS_TOKEN_EXPIRATION_TIME = 3600
550542
;;

docs/content/administration/command-line.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ for automatic deployments.
350350
- `secret`:
351351
- Options:
352352
- `INTERNAL_TOKEN`: Token used for an internal API call authentication.
353-
- `JWT_SECRET`: LFS & OAUTH2 JWT authentication secret (LFS_JWT_SECRET is aliased to this option for backwards compatibility).
353+
- `GENERAL_WEB_SECRET`: A general secret used for signing or encrypting web related contents (CSRF token, JWT token, validation, etc).
354354
- `SECRET_KEY`: Global secret key.
355355
- Examples:
356356
- `gitea generate secret INTERNAL_TOKEN`
357-
- `gitea generate secret JWT_SECRET`
357+
- `gitea generate secret GENERAL_WEB_SECRET`
358358
- `gitea generate secret SECRET_KEY`
359359

360360
### keys

docs/content/administration/command-line.zh-cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ menu:
330330
- `secret`:
331331
- 选项:
332332
- `INTERNAL_TOKEN`: 用于内部 API 调用身份验证的令牌。
333-
- `JWT_SECRET`: 用于 LFS 和 OAUTH2 JWT 身份验证的密钥(LFS_JWT_SECRET 是此选项的别名,用于向后兼容)
333+
- `GENERAL_WEB_SECRET`: 用于签名或者加密 web 内容(例如 JWT、CSRF、验证等)的通用密钥
334334
- `SECRET_KEY`: 全局密钥。
335335
- 示例:
336336
- `gitea generate secret INTERNAL_TOKEN`
337-
- `gitea generate secret JWT_SECRET`
337+
- `gitea generate secret GENERAL_WEB_SECRET`
338338
- `gitea generate secret SECRET_KEY`
339339

340340
### keys

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ The following configuration set `Content-Type: application/vnd.android.package-a
368368
- `LANDING_PAGE`: **home**: Landing page for unauthenticated users \[home, explore, organizations, login, **custom**\]. Where custom would instead be any URL such as "/org/repo" or even `https://anotherwebsite.com`
369369
- `LFS_START_SERVER`: **false**: Enables Git LFS support.
370370
- `LFS_CONTENT_PATH`: **%(APP_DATA_PATH)s/lfs**: Default LFS content path. (if it is on local storage.) **DEPRECATED** use settings in `[lfs]`.
371-
- `LFS_JWT_SECRET`: **_empty_**: LFS authentication secret, change this a unique string.
372-
- `LFS_JWT_SECRET_URI`: **_empty_**: Instead of defining LFS_JWT_SECRET in the configuration, this configuration option can be used to give Gitea a path to a file that contains the secret (example value: `file:/etc/gitea/lfs_jwt_secret`)
373371
- `LFS_HTTP_AUTH_EXPIRY`: **24h**: LFS authentication validity period in time.Duration, pushes taking longer than this may fail.
374372
- `LFS_MAX_FILE_SIZE`: **0**: Maximum allowed LFS file size in bytes (Set to 0 for no limit).
375373
- `LFS_LOCKS_PAGING_NUM`: **50**: Maximum number of LFS Locks returned per page.
@@ -556,6 +554,8 @@ And the following unique queues:
556554
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.
557555
- `INTERNAL_TOKEN`: **\<random at every install if no uri set\>**: Secret used to validate communication within Gitea binary.
558556
- `INTERNAL_TOKEN_URI`: **_empty_**: Instead of defining INTERNAL_TOKEN in the configuration, this configuration option can be used to give Gitea a path to a file that contains the internal token (example value: `file:/etc/gitea/internal_token`)
557+
- `GENERAL_WEB_SECRET`: **\<random at every install if no uri set\>**: A general secret used for signing or encrypting web related contents (CSRF token, JWT token, validation, etc).
558+
- `GENERAL_WEB_SECRET_URI`: **_empty_**: Instead of defining GENERAL_WEB_SECRET in the configuration, this configuration option can be used to give Gitea a path to a file that contains the general web secret (example value: `file:/etc/gitea/genearl_web_secret`)
559559
- `PASSWORD_HASH_ALGO`: **pbkdf2**: The hash algorithm to use \[argon2, pbkdf2, pbkdf2_v1, pbkdf2_hi, scrypt, bcrypt\], argon2 and scrypt will spend significant amounts of memory.
560560
- Note: The default parameters for `pbkdf2` hashing have changed - the previous settings are available as `pbkdf2_v1` but are not recommended.
561561
- The hash functions may be tuned by using `$` after the algorithm:
@@ -1121,8 +1121,6 @@ This section only does "set" config, a removed config key from this section won'
11211121
- `REFRESH_TOKEN_EXPIRATION_TIME`: **730**: Lifetime of an OAuth2 refresh token in hours
11221122
- `INVALIDATE_REFRESH_TOKENS`: **false**: Check if refresh token has already been used
11231123
- `JWT_SIGNING_ALGORITHM`: **RS256**: Algorithm used to sign OAuth2 tokens. Valid values: \[`HS256`, `HS384`, `HS512`, `RS256`, `RS384`, `RS512`, `ES256`, `ES384`, `ES512`\]
1124-
- `JWT_SECRET`: **_empty_**: OAuth2 authentication secret for access and refresh tokens, change this to a unique string. This setting is only needed if `JWT_SIGNING_ALGORITHM` is set to `HS256`, `HS384` or `HS512`.
1125-
- `JWT_SECRET_URI`: **_empty_**: Instead of defining JWT_SECRET in the configuration, this configuration option can be used to give Gitea a path to a file that contains the secret (example value: `file:/etc/gitea/oauth2_jwt_secret`)
11261124
- `JWT_SIGNING_PRIVATE_KEY_FILE`: **jwt/private.pem**: Private key file path used to sign OAuth2 tokens. The path is relative to `APP_DATA_PATH`. This setting is only needed if `JWT_SIGNING_ALGORITHM` is set to `RS256`, `RS384`, `RS512`, `ES256`, `ES384` or `ES512`. The file must contain a RSA or ECDSA private key in the PKCS8 format. If no key exists a 4096 bit key will be created for you.
11271125
- `MAX_TOKEN_LENGTH`: **32767**: Maximum length of token/cookie to accept from OAuth2 provider
11281126
- `DEFAULT_APPLICATIONS`: **git-credential-oauth, git-credential-manager, tea**: Pre-register OAuth applications for some services on startup. See the [OAuth2 documentation](/development/oauth2-provider.md) for the list of available options.

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ menu:
355355
- `LANDING_PAGE`: **home**:未经身份验证用户的登录页面 \[home, explore, organizations, login, **custom**]。其中 custom 可以是任何 URL,例如 "/org/repo" 或甚至是 `https://anotherwebsite.com`
356356
- `LFS_START_SERVER`: **false**:启用 Git LFS 支持。
357357
- `LFS_CONTENT_PATH`: **%(APP_DATA_PATH)s/lfs**:默认的 LFS 内容路径(如果它在本地存储中)。**已弃用**,请使用 `[lfs]` 中的设置。
358-
- `LFS_JWT_SECRET`: **_empty_**:LFS 身份验证密钥,将其更改为唯一的字符串。
359-
- `LFS_JWT_SECRET_URI`: **_empty_**:代替在配置中定义 LFS_JWT_SECRET,可以使用此配置选项为 Gitea 提供包含密钥的文件的路径(示例值:`file:/etc/gitea/lfs_jwt_secret`)。
360358
- `LFS_HTTP_AUTH_EXPIRY`: **24h**:LFS 身份验证的有效期,以 time.Duration 表示,超过此期限的推送可能会失败。
361359
- `LFS_MAX_FILE_SIZE`: **0**:允许的最大 LFS 文件大小(以字节为单位,设置为 0 为无限制)。
362360
- `LFS_LOCKS_PAGING_NUM`: **50**:每页返回的最大 LFS 锁定数。
@@ -1051,8 +1049,6 @@ Gitea 创建以下非唯一队列:
10511049
- `REFRESH_TOKEN_EXPIRATION_TIME`**730**:OAuth2刷新令牌的生命周期,以小时为单位。
10521050
- `INVALIDATE_REFRESH_TOKENS`**false**:检查刷新令牌是否已被使用。
10531051
- `JWT_SIGNING_ALGORITHM`**RS256**:用于签署OAuth2令牌的算法。有效值:[`HS256``HS384``HS512``RS256``RS384``RS512``ES256``ES384``ES512`]
1054-
- `JWT_SECRET`**_empty_**:OAuth2访问和刷新令牌的身份验证密钥,请将其更改为唯一的字符串。仅当`JWT_SIGNING_ALGORITHM`设置为`HS256``HS384``HS512`时才需要此设置。
1055-
- `JWT_SECRET_URI`**_empty_**:可以使用此配置选项,而不是在配置中定义`JWT_SECRET`,以向Gitea提供包含密钥的文件的路径(示例值:`file:/etc/gitea/oauth2_jwt_secret`)。
10561052
- `JWT_SIGNING_PRIVATE_KEY_FILE`**jwt/private.pem**:用于签署OAuth2令牌的私钥文件路径。路径相对于`APP_DATA_PATH`。仅当`JWT_SIGNING_ALGORITHM`设置为`RS256``RS384``RS512``ES256``ES384``ES512`时才需要此设置。文件必须包含PKCS8格式的RSA或ECDSA私钥。如果不存在密钥,则将为您创建一个4096位密钥。
10571053
- `MAX_TOKEN_LENGTH`**32767**:从OAuth2提供者接受的令牌/cookie的最大长度。
10581054
- `DEFAULT_APPLICATIONS`**git-credential-oauth,git-credential-manager, tea**:在启动时预注册用于某些服务的OAuth应用程序。有关可用选项列表,请参阅[OAuth2文档](/development/oauth2-provider.md)

modules/generate/generate.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,29 @@ func NewInternalToken() (string, error) {
3939
return internalToken, nil
4040
}
4141

42-
const defaultJwtSecretLen = 32
42+
func DecodeGeneralWebSecretBase64(src string) ([]byte, error) {
43+
return decodeGeneralSecretBase64(src, 32)
44+
}
45+
46+
func NewGeneralWebSecretWithBase64() ([]byte, string, error) {
47+
return newGeneralSecretWithBase64(32)
48+
}
4349

44-
// DecodeJwtSecretBase64 decodes a base64 encoded jwt secret into bytes, and check its length
45-
func DecodeJwtSecretBase64(src string) ([]byte, error) {
50+
// decodeGeneralSecretBase64 decodes a base64 encoded secret into bytes, and check its length
51+
func decodeGeneralSecretBase64(src string, length int) ([]byte, error) {
4652
encoding := base64.RawURLEncoding
4753
decoded := make([]byte, encoding.DecodedLen(len(src))+3)
4854
if n, err := encoding.Decode(decoded, []byte(src)); err != nil {
4955
return nil, err
50-
} else if n != defaultJwtSecretLen {
51-
return nil, fmt.Errorf("invalid base64 decoded length: %d, expects: %d", n, defaultJwtSecretLen)
56+
} else if n != length {
57+
return nil, fmt.Errorf("invalid base64 decoded length: %d, expects: %d", n, length)
5258
}
53-
return decoded[:defaultJwtSecretLen], nil
59+
return decoded[:length], nil
5460
}
5561

56-
// NewJwtSecretWithBase64 generates a jwt secret with its base64 encoded value intended to be used for saving into config file
57-
func NewJwtSecretWithBase64() ([]byte, string, error) {
58-
bytes := make([]byte, defaultJwtSecretLen)
62+
// newGeneralSecretWithBase64 generates a secret with its base64 encoded value intended to be used for saving into config file
63+
func newGeneralSecretWithBase64(length int) ([]byte, string, error) {
64+
bytes := make([]byte, length)
5965
_, err := io.ReadFull(rand.Reader, bytes)
6066
if err != nil {
6167
return nil, "", err

modules/setting/lfs.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ package setting
66
import (
77
"fmt"
88
"time"
9-
10-
"code.gitea.io/gitea/modules/generate"
119
)
1210

1311
// LFS represents the configuration for Git LFS
1412
var LFS = struct {
1513
StartServer bool `ini:"LFS_START_SERVER"`
16-
JWTSecretBytes []byte `ini:"-"`
1714
HTTPAuthExpiry time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
1815
MaxFileSize int64 `ini:"LFS_MAX_FILE_SIZE"`
1916
LocksPagingNum int `ini:"LFS_LOCKS_PAGING_NUM"`
@@ -54,29 +51,5 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
5451

5552
LFS.HTTPAuthExpiry = sec.Key("LFS_HTTP_AUTH_EXPIRY").MustDuration(24 * time.Hour)
5653

57-
if !LFS.StartServer || !InstallLock {
58-
return nil
59-
}
60-
61-
jwtSecretBase64 := loadSecret(rootCfg.Section("server"), "LFS_JWT_SECRET_URI", "LFS_JWT_SECRET")
62-
LFS.JWTSecretBytes, err = generate.DecodeJwtSecretBase64(jwtSecretBase64)
63-
if err != nil {
64-
LFS.JWTSecretBytes, jwtSecretBase64, err = generate.NewJwtSecretWithBase64()
65-
if err != nil {
66-
return fmt.Errorf("error generating JWT Secret for custom config: %v", err)
67-
}
68-
69-
// Save secret
70-
saveCfg, err := rootCfg.PrepareSaving()
71-
if err != nil {
72-
return fmt.Errorf("error saving JWT Secret for custom config: %v", err)
73-
}
74-
rootCfg.Section("server").Key("LFS_JWT_SECRET").SetValue(jwtSecretBase64)
75-
saveCfg.Section("server").Key("LFS_JWT_SECRET").SetValue(jwtSecretBase64)
76-
if err := saveCfg.Save(); err != nil {
77-
return fmt.Errorf("error saving JWT Secret for custom config: %v", err)
78-
}
79-
}
80-
8154
return nil
8255
}

modules/setting/oauth2.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ package setting
66
import (
77
"math"
88
"path/filepath"
9-
"sync/atomic"
109

11-
"code.gitea.io/gitea/modules/generate"
1210
"code.gitea.io/gitea/modules/log"
1311
)
1412

@@ -130,50 +128,7 @@ func loadOAuth2From(rootCfg ConfigProvider) {
130128
return
131129
}
132130

133-
jwtSecretBase64 := loadSecret(sec, "JWT_SECRET_URI", "JWT_SECRET")
134-
135131
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
136132
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)
137133
}
138-
139-
if InstallLock {
140-
jwtSecretBytes, err := generate.DecodeJwtSecretBase64(jwtSecretBase64)
141-
if err != nil {
142-
jwtSecretBytes, jwtSecretBase64, err = generate.NewJwtSecretWithBase64()
143-
if err != nil {
144-
log.Fatal("error generating JWT secret: %v", err)
145-
}
146-
saveCfg, err := rootCfg.PrepareSaving()
147-
if err != nil {
148-
log.Fatal("save oauth2.JWT_SECRET failed: %v", err)
149-
}
150-
rootCfg.Section("oauth2").Key("JWT_SECRET").SetValue(jwtSecretBase64)
151-
saveCfg.Section("oauth2").Key("JWT_SECRET").SetValue(jwtSecretBase64)
152-
if err := saveCfg.Save(); err != nil {
153-
log.Fatal("save oauth2.JWT_SECRET failed: %v", err)
154-
}
155-
}
156-
generalSigningSecret.Store(&jwtSecretBytes)
157-
}
158-
}
159-
160-
// generalSigningSecret is used as container for a []byte value
161-
// instead of an additional mutex, we use CompareAndSwap func to change the value thread save
162-
var generalSigningSecret atomic.Pointer[[]byte]
163-
164-
func GetGeneralTokenSigningSecret() []byte {
165-
old := generalSigningSecret.Load()
166-
if old == nil || len(*old) == 0 {
167-
jwtSecret, _, err := generate.NewJwtSecretWithBase64()
168-
if err != nil {
169-
log.Fatal("Unable to generate general JWT secret: %s", err.Error())
170-
}
171-
if generalSigningSecret.CompareAndSwap(old, &jwtSecret) {
172-
// FIXME: in main branch, the signing token should be refactored (eg: one unique for LFS/OAuth2/etc ...)
173-
LogStartupProblem(1, log.WARN, "OAuth2 is not enabled, unable to use a persistent signing secret, a new one is generated, which is not persistent between restarts and cluster nodes")
174-
return jwtSecret
175-
}
176-
return *generalSigningSecret.Load()
177-
}
178-
return *old
179134
}

modules/setting/oauth2_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,9 @@ package setting
66
import (
77
"testing"
88

9-
"code.gitea.io/gitea/modules/generate"
10-
"code.gitea.io/gitea/modules/test"
11-
129
"github.com/stretchr/testify/assert"
1310
)
1411

15-
func TestGetGeneralSigningSecret(t *testing.T) {
16-
// when there is no general signing secret, it should be generated, and keep the same value
17-
assert.Nil(t, generalSigningSecret.Load())
18-
s1 := GetGeneralTokenSigningSecret()
19-
assert.NotNil(t, s1)
20-
s2 := GetGeneralTokenSigningSecret()
21-
assert.Equal(t, s1, s2)
22-
23-
// the config value should always override any pre-generated value
24-
cfg, _ := NewConfigProviderFromData(`
25-
[oauth2]
26-
JWT_SECRET = BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
27-
`)
28-
defer test.MockVariableValue(&InstallLock, true)()
29-
loadOAuth2From(cfg)
30-
actual := GetGeneralTokenSigningSecret()
31-
expected, _ := generate.DecodeJwtSecretBase64("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")
32-
assert.Len(t, actual, 32)
33-
assert.EqualValues(t, expected, actual)
34-
}
35-
3612
func TestOauth2DefaultApplications(t *testing.T) {
3713
cfg, _ := NewConfigProviderFromData(``)
3814
loadOAuth2From(cfg)

0 commit comments

Comments
 (0)