Tighten Google Chat webhook validation and settings response
Restrict the decoded key and token to a URL-safe ASCII alphabet so the 16-character minimum and the four-character masked tail measure the same thing; a token of a few multi-byte characters could otherwise be shown in full (MQ-165-01). Validate the raw query as exactly key=…&token=…, refusing empty segments, a second "?", reordered, extra or repeated parameters (MQ-165-02). Drop configured and updated_at from the settings response so it is the four-field contract: space_label, url_masked, last_test_at, last_test_status; url_masked is null exactly when nothing is stored (MQ-165-03). Task: 919e9422-3a41-4f1f-8967-77da17f5f9f3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -131,7 +131,7 @@ func TestChatWebhookAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
rec, body := call(http.MethodGet, chatWebhookPath, "")
|
||||
if rec.Code != http.StatusOK || body["configured"] != false || body["url_masked"] != nil || body["space_label"] != nil {
|
||||
if rec.Code != http.StatusOK || body["url_masked"] != nil || body["space_label"] != nil || body["last_test_at"] != nil || body["last_test_status"] != nil || len(body) != 4 {
|
||||
t.Errorf("GET unconfigured = %d %v", rec.Code, body)
|
||||
}
|
||||
rec, body = call(http.MethodPost, chatWebhookTestPath, "")
|
||||
@@ -160,8 +160,8 @@ func TestChatWebhookAPI(t *testing.T) {
|
||||
|
||||
rec, body = call(http.MethodPut, chatWebhookPath, `{"url":"`+testChatHook+`","space_label":"Family dinner"}`)
|
||||
wantMasked := "https://chat.googleapis.com/v1/spaces/AAQA1b2C3d4/messages?key=…&token=…ZxQ="
|
||||
if rec.Code != http.StatusOK || body["configured"] != true || body["space_label"] != "Family dinner" || body["url_masked"] != wantMasked ||
|
||||
body["last_test_at"] != nil || body["last_test_status"] != nil {
|
||||
if rec.Code != http.StatusOK || body["space_label"] != "Family dinner" || body["url_masked"] != wantMasked ||
|
||||
body["last_test_at"] != nil || body["last_test_status"] != nil || len(body) != 4 {
|
||||
t.Errorf("PUT = %d %v", rec.Code, body)
|
||||
}
|
||||
if _, ok := body["url"]; ok {
|
||||
|
||||
Reference in New Issue
Block a user