MCPcopy Index your code
hub / github.com/go-task/task / TestBuildHTTPClient_CertAndKey

Function TestBuildHTTPClient_CertAndKey

taskfile/node_http_test.go:152–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

150}
151
152func TestBuildHTTPClient_CertAndKey(t *testing.T) {
153 t.Parallel()
154
155 // Create temporary cert and key files
156 tempDir := t.TempDir()
157 certPath := filepath.Join(tempDir, "client.crt")
158 keyPath := filepath.Join(tempDir, "client.key")
159
160 // Generate a self-signed certificate and key for testing
161 cert, key := generateTestCertAndKey(t)
162 err := os.WriteFile(certPath, cert, 0o600)
163 require.NoError(t, err)
164 err = os.WriteFile(keyPath, key, 0o600)
165 require.NoError(t, err)
166
167 client, err := buildHTTPClient(false, "", certPath, keyPath)
168 require.NoError(t, err)
169 require.NotNil(t, client)
170 assert.NotEqual(t, http.DefaultClient, client)
171
172 // Check that client certificate is set
173 transport, ok := client.Transport.(*http.Transport)
174 require.True(t, ok)
175 require.NotNil(t, transport.TLSClientConfig)
176 assert.Len(t, transport.TLSClientConfig.Certificates, 1)
177}
178
179func TestBuildHTTPClient_CertNotFound(t *testing.T) {
180 t.Parallel()

Callers

nothing calls this directly

Calls 3

generateTestCertAndKeyFunction · 0.85
buildHTTPClientFunction · 0.85
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…