Files
seaweedfs/weed/credential/credential_manager_config_file_test.go
T
a2a7a589bb filer: keep the content out of S3 config parse errors (#13202)
* filer: keep the content out of S3 config parse errors

protojson's errors quote the token they reject, and in these files that
can be a secret key or KMS key material, so a config that didn't parse
could log part of a key. The error now gives the line and column, the
field's type and name for a value of the wrong type, or says the file
ends early. Syntax errors come from encoding/json, which gives an offset
instead of a quote, so protojson's text is only read for valid JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: keep codespell from flagging a parse error test case

Codespell reads `tru` in `{"é": tru#` as a misspelling. `nul#` fails at
the same column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* credential: run the store interface tests on the memory store

The tests took the first registered store, which depends on package
init order: once filer_etc registered first they ran against a filer
that is not there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* credential: keep the content out of static S3 config file parse errors

LoadS3ConfigFile parsed the -s3.config file with protojson directly, so
the filer logged a rejected token such as a secret key. It now uses
ParseS3ConfigurationFromBytes like the other readers of that file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-12-01 10:56:25 -08:00

27 lines
828 B
Go

package credential
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestLoadS3ConfigFileKeepsTheContentOutOfParseErrors(t *testing.T) {
path := filepath.Join(t.TempDir(), "s3.json")
content := `{"identities": [{"name": "a", "credentials": [{"accessKey": "AK", "secretKey": 102030405060708090}]}]}`
if err := os.WriteFile(path, []byte(content), 0600); err != nil {
t.Fatal(err)
}
err := (&CredentialManager{}).LoadS3ConfigFile(path)
if err == nil {
t.Fatal("expected a parse error")
}
if strings.Contains(err.Error(), "102030405060708090") {
t.Fatalf("parse error quotes the secret key: %v", err)
}
if want := "invalid configuration at line 1, column 80: invalid value for string field secretKey"; !strings.HasSuffix(err.Error(), want) {
t.Fatalf("got %v, want it to end with %s", err, want)
}
}