MCPcopy Create free account
hub / github.com/cloudflare/cfssl / testAuthSignFile

Function testAuthSignFile

api/sign/sign_test.go:443–492  ·  view source on GitHub ↗
(t *testing.T, hosts []string, subject *signer.Subject, csrFile string, profile *config.SigningProfile)

Source from the content-addressed store, hash-verified

441}
442
443func testAuthSignFile(t *testing.T, hosts []string, subject *signer.Subject, csrFile string, profile *config.SigningProfile) (resp *http.Response, body []byte) {
444 ts := newAuthSignServer(t)
445 defer ts.Close()
446
447 var csrPEM []byte
448 if csrFile != "" {
449 var err error
450 csrPEM, err = os.ReadFile(csrFile)
451 if err != nil {
452 t.Fatal(err)
453 }
454 }
455 obj := map[string]interface{}{}
456 if hosts != nil {
457 obj["hosts"] = hosts
458 }
459 if subject != nil {
460 obj["subject"] = subject
461 }
462 if len(csrPEM) > 0 {
463 obj["certificate_request"] = string(csrPEM)
464 }
465
466 reqBlob, err := json.Marshal(obj)
467 if err != nil {
468 t.Fatal(err)
469 }
470
471 var aReq auth.AuthenticatedRequest
472 aReq.Request = reqBlob
473 aReq.Token, err = profile.Provider.Token(aReq.Request)
474 if err != nil {
475 t.Fatal(err)
476 }
477
478 blob, err := json.Marshal(aReq)
479 if err != nil {
480 t.Fatal(err)
481 }
482
483 resp, err = http.Post(ts.URL, "application/json", bytes.NewReader(blob))
484 if err != nil {
485 t.Fatal(err)
486 }
487 body, err = io.ReadAll(resp.Body)
488 if err != nil {
489 t.Fatal(err)
490 }
491 return
492}
493
494func newAuthSignServer(t *testing.T) *httptest.Server {
495 ts := httptest.NewServer(newTestAuthHandler(t))

Callers 1

TestAuthSignFunction · 0.85

Calls 3

newAuthSignServerFunction · 0.85
TokenMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…