MCPcopy
hub / github.com/nats-io/nats.go / TestUserCredentialsChainedFile

Function TestUserCredentialsChainedFile

test/nats_test.go:263–290  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

261}
262
263func TestUserCredentialsChainedFile(t *testing.T) {
264 if server.VERSION[0] == '1' {
265 t.Skip()
266 }
267 ts := runTrustServer()
268 defer ts.Shutdown()
269
270 chainedFile := createTmpFile(t, []byte(chained))
271 defer os.Remove(chainedFile)
272
273 url := fmt.Sprintf("nats://127.0.0.1:%d", TEST_PORT)
274 nc, err := nats.Connect(url, nats.UserCredentials(chainedFile))
275 if err != nil {
276 t.Fatalf("Expected to connect, got %v", err)
277 }
278 nc.Close()
279
280 chainedFile = createTmpFile(t, []byte("invalid content"))
281 defer os.Remove(chainedFile)
282 nc, err = nats.Connect(url, nats.UserCredentials(chainedFile))
283 if err == nil || !strings.Contains(err.Error(),
284 "error signing nonce: unable to extract key pair from file") {
285 if nc != nil {
286 nc.Close()
287 }
288 t.Fatalf("Expected error about invalid creds file, got %q", err)
289 }
290}
291
292func TestReconnectMissingCredentials(t *testing.T) {
293 ts := runTrustServer()

Callers

nothing calls this directly

Calls 6

runTrustServerFunction · 0.85
ConnectMethod · 0.80
FatalfMethod · 0.80
createTmpFileFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected