Skip to content

Commit

Permalink
Add further PNA test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nullun committed Sep 17, 2024
1 parent 7ff914b commit 1aa69a6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions api/handlers_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2613,3 +2613,39 @@ func TestAccounts(t *testing.T) {
assert.Equal(t, uint64(1000000000000), (*acctA.Account.CreatedAssets)[0].Params.Total)
assert.Equal(t, "bogo", *(*acctA.Account.CreatedAssets)[0].Params.UnitName)
}

func TestPNAHeader(t *testing.T) {
db, shutdownFunc := setupIdb(t, test.MakeGenesis())
defer shutdownFunc()

//////////
// When // We preflight an endpoint with the PNA "Request" header set
//////////

serverCtx, serverCancel := context.WithCancel(context.Background())
defer serverCancel()
opts := defaultOpts
opts.EnablePrivateNetworkAccessHeader = true
listenAddr := "localhost:8894"
go Serve(serverCtx, listenAddr, db, nil, logrus.New(), opts)

waitForServer(t, listenAddr)

path := "/health"
client := &http.Client{}
req, err := http.NewRequest("OPTIONS", "http://"+listenAddr+path, nil)
require.NoError(t, err)
req.Header.Add("Access-Control-Request-Private-Network", "true")

t.Log("making HTTP request path", req.URL)

resp, err := client.Do(req)
require.NoError(t, err)

//////////
// Then // We expect the PNA "Allow" header to be set
//////////

require.Equal(t, resp.Header.Get("Access-Control-Allow-Private-Network"), "true")
defer resp.Body.Close()
}

0 comments on commit 1aa69a6

Please sign in to comment.