Skip to content

Commit 15769c0

Browse files
Slachaider-chat-bot
andcommitted
feat: make JWTSecretKey optional in JWE configuration, add test for missing jwt-secret-key, make --jwt-secret-key optional to use JSON serialization+JWE encryption instead of JWT signing+JWE encryption, fix #25
Signed-off-by: Slach <[email protected]> Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <[email protected]>
1 parent 1fe2a37 commit 15769c0

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v1.1.1
2+
IMPROVEMENTS
3+
- make `--jwt-secret-key` optional to use JSON serialization+JWE encryption instead of JWT signing+JWE encryption, fix https://github.com/Altinity/altinity-mcp/issues/25
4+
15
# v1.1.0
26
IMPROVEMENTS
37
- switch to go 1.25, update go.mod

cmd/altinity-mcp/main.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ func (a *application) jweTokenGeneratorHandler(w http.ResponseWriter, r *http.Re
335335
}
336336

337337
cfg := a.GetCurrentConfig()
338-
if cfg.Server.JWE.JWESecretKey == "" || cfg.Server.JWE.JWTSecretKey == "" {
339-
http.Error(w, "Missing JWE or JWT secret key", http.StatusInternalServerError)
338+
if cfg.Server.JWE.JWESecretKey == "" {
339+
http.Error(w, "Missing JWE secret key", http.StatusInternalServerError)
340340
return
341341
}
342342
if !cfg.Server.JWE.Enabled {
@@ -1096,13 +1096,10 @@ func newApplication(ctx context.Context, cfg config.Config, cmd CommandInterface
10961096
} else {
10971097
log.Debug().Msg("JWE encryption enabled, skipping default ClickHouse connection test")
10981098

1099-
// Validate both secrets are set when JWE auth is enabled
1099+
// Validate JWE secret key is set when JWE auth is enabled
11001100
if cfg.Server.JWE.JWESecretKey == "" {
11011101
return nil, fmt.Errorf("JWE encryption is enabled but no JWE secret key is provided")
11021102
}
1103-
if cfg.Server.JWE.JWTSecretKey == "" {
1104-
return nil, fmt.Errorf("JWE encryption is enabled but no JWT secret key is provided")
1105-
}
11061103
}
11071104

11081105
// Create MCP server

cmd/altinity-mcp/main_test.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ func TestNewApplication(t *testing.T) {
10611061
JWE: config.JWEConfig{
10621062
Enabled: true,
10631063
JWESecretKey: "jwe-secret",
1064-
JWTSecretKey: "", // Empty secret key should cause error
1064+
JWTSecretKey: "", // Empty secret key is now allowed
10651065
},
10661066
},
10671067
}
@@ -1077,9 +1077,38 @@ func TestNewApplication(t *testing.T) {
10771077

10781078
ctx := context.Background()
10791079
app, err := newApplication(ctx, cfg, cmd)
1080-
require.Error(t, err)
1081-
require.Nil(t, app)
1082-
require.Contains(t, err.Error(), "JWE encryption is enabled but no JWT secret key is provided")
1080+
require.NoError(t, err)
1081+
require.NotNil(t, app)
1082+
1083+
claims := map[string]interface{}{
1084+
"host": "localhost",
1085+
"port": 8123,
1086+
"database": "default",
1087+
"username": "default",
1088+
"protocol": "http",
1089+
"exp": time.Now().Add(time.Hour).Unix(),
1090+
}
1091+
body, err := json.Marshal(claims)
1092+
require.NoError(t, err)
1093+
1094+
req := httptest.NewRequest(http.MethodPost, "/jwe-token-generator", bytes.NewReader(body))
1095+
w := httptest.NewRecorder()
1096+
1097+
app.jweTokenGeneratorHandler(w, req)
1098+
1099+
require.Equal(t, http.StatusOK, w.Code)
1100+
1101+
var resp map[string]string
1102+
err = json.NewDecoder(w.Body).Decode(&resp)
1103+
require.NoError(t, err)
1104+
require.Contains(t, resp, "token")
1105+
1106+
// Verify the token
1107+
parsedClaims, err := jwe_auth.ParseAndDecryptJWE(resp["token"], []byte(cfg.Server.JWE.JWESecretKey), []byte(cfg.Server.JWE.JWTSecretKey))
1108+
require.NoError(t, err)
1109+
require.Equal(t, "localhost", parsedClaims["host"])
1110+
require.Equal(t, float64(8123), parsedClaims["port"])
1111+
app.Close()
10831112
})
10841113

10851114
t.Run("jwe_enabled_with_secret", func(t *testing.T) {

0 commit comments

Comments
 (0)