File: client_windows_test.go

package info (click to toggle)
golang-github-spiffe-go-spiffe 2.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,116 kB
  • sloc: makefile: 157
file content (49 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//go:build windows
// +build windows

package workloadapi

import (
	"context"
	"strings"
	"testing"

	"github.com/spiffe/go-spiffe/v2/internal/test"
	"github.com/spiffe/go-spiffe/v2/internal/test/fakeworkloadapi"
	"github.com/stretchr/testify/require"
)

func TestWithNamedPipeName(t *testing.T) {
	ca := test.NewCA(t, td)
	wl := fakeworkloadapi.NewWithNamedPipeListener(t)
	defer wl.Stop()

	pipeName := strings.TrimPrefix(wl.Addr(), "npipe:")
	c, err := New(context.Background(), WithNamedPipeName(pipeName))
	require.NoError(t, err)
	defer c.Close()
	require.Equal(t, pipeName, c.config.namedPipeName)

	resp := &fakeworkloadapi.X509SVIDResponse{
		Bundle: ca.X509Bundle(),
		SVIDs:  makeX509SVIDs(ca, "internal", fooID, barID),
	}
	wl.SetX509SVIDResponse(resp)
	svid, err := c.FetchX509SVID(context.Background())
	require.NoError(t, err)
	assertX509SVID(t, svid, fooID, resp.SVIDs[0].Certificates, "internal")
}

func TestWithNamedPipeNameError(t *testing.T) {
	wl := fakeworkloadapi.NewWithNamedPipeListener(t)
	defer wl.Stop()

	c, err := New(context.Background(), WithNamedPipeName("ohno"))
	require.NoError(t, err)
	defer c.Close()

	wl.SetX509SVIDResponse(&fakeworkloadapi.X509SVIDResponse{})
	_, err = c.FetchX509SVID(context.Background())
	require.Error(t, err)
	require.Contains(t, err.Error(), `ohno: The system cannot find the file specified`)
}