Skip to content

Commit 0168560

Browse files
committed
csigrpc: test with updated CSI spec
This is a copy of the CSI 1.0.0 spec and build rules with more fields added that test various special cases, in particular the addition of secrets in nested data structures (simple structs, lists, maps).
1 parent 253ed25 commit 0168560

File tree

7 files changed

+7934
-7
lines changed

7 files changed

+7934
-7
lines changed

pkg/csigrpc/secrets_test.go

+45-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/container-storage-interface/spec/lib/go/csi"
24+
"github.com/kubernetes-csi/csi-lib-utils/test/pkg/csi-spec/csitest"
2425
"github.com/stretchr/testify/assert"
2526
)
2627

@@ -72,13 +73,50 @@ func TestStripSecrets(t *testing.T) {
7273
{false, "false"},
7374
{&csi.CreateVolumeRequest{}, `{}`},
7475
{createVolume, `{"accessibility_requirements":{"requisite":[{"segments":{"foo":"bar","x":"y"}},{"segments":{"a":"b"}}]},"capacity_range":{"required_bytes":1024},"name":"foo","secrets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}}}]}`},
75-
76-
// There is currently no test case that can verify
77-
// that recursive stripping works, because there is no
78-
// message where that is necessary. The code
79-
// nevertheless implements it and it has been verified
80-
// manually that it recurses properly for single and
81-
// repeated values. One-of might require further work.
76+
{&csitest.CreateVolumeRequest{}, `{}`},
77+
{&csitest.CreateVolumeRequest{
78+
CapacityRange: &csitest.CapacityRange{
79+
RequiredBytes: 1024,
80+
},
81+
MaybeSecretMap: map[int64]*csitest.VolumeCapability{
82+
1: &csitest.VolumeCapability{ArraySecret: "aaa"},
83+
2: &csitest.VolumeCapability{ArraySecret: "bbb"},
84+
},
85+
Name: "foo",
86+
NewSecretInt: 42,
87+
Seecreets: map[string]string{
88+
secretName: secretValue,
89+
"secret-xyz": "987",
90+
},
91+
VolumeCapabilities: []*csitest.VolumeCapability{
92+
&csitest.VolumeCapability{
93+
AccessType: &csitest.VolumeCapability_Mount{
94+
Mount: &csitest.VolumeCapability_MountVolume{
95+
FsType: "ext4",
96+
},
97+
},
98+
ArraySecret: "knock knock",
99+
},
100+
&csitest.VolumeCapability{
101+
ArraySecret: "Who's there?",
102+
},
103+
},
104+
VolumeContentSource: &csitest.VolumeContentSource{
105+
Type: &csitest.VolumeContentSource_Volume{
106+
Volume: &csitest.VolumeContentSource_VolumeSource{
107+
VolumeId: "abc",
108+
OneofSecretField: "hello",
109+
},
110+
},
111+
NestedSecretField: "world",
112+
},
113+
},
114+
// Secrets are *not* removed from all fields yet. This will have to be fixed one way or another
115+
// before the CSI spec can start using secrets there (currently it doesn't).
116+
// The test is still useful because it shows that also complicated fields get serialized.
117+
// `{"capacity_range":{"required_bytes":1024},"maybe_secret_map":{"1":{"AccessType":null,"array_secret":"***stripped***"},"2":{"AccessType":null,"array_secret":"***stripped***"}},"name":"foo","new_secret_int":"***stripped***","seecreets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}},"array_secret":"***stripped***"},{"AccessType":null,"array_secret":"***stripped***"}],"volume_content_source":{"Type":{"Volume":{"oneof_secret_field":"***stripped***","volume_id":"abc"}},"nested_secret_field":"***stripped***"}}`,
118+
`{"capacity_range":{"required_bytes":1024},"maybe_secret_map":{"1":{"AccessType":null,"array_secret":"aaa"},"2":{"AccessType":null,"array_secret":"bbb"}},"name":"foo","new_secret_int":"***stripped***","seecreets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}},"array_secret":"***stripped***"},{"AccessType":null,"array_secret":"***stripped***"}],"volume_content_source":{"Type":{"Volume":{"oneof_secret_field":"hello","volume_id":"abc"}},"nested_secret_field":"***stripped***"}}`,
119+
},
82120
}
83121

84122
for _, c := range cases {

test/pkg/csi-spec/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/protoc
2+
/protoc-gen-go
3+
/csi.a
4+
/.protoc
5+
.build

test/pkg/csi-spec/Makefile

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
all: build
2+
3+
########################################################################
4+
## GOLANG ##
5+
########################################################################
6+
7+
# If GOPATH isn't defined then set its default location.
8+
ifeq (,$(strip $(GOPATH)))
9+
GOPATH := $(HOME)/go
10+
else
11+
# If GOPATH is already set then update GOPATH to be its own
12+
# first element.
13+
GOPATH := $(word 1,$(subst :, ,$(GOPATH)))
14+
endif
15+
export GOPATH
16+
17+
18+
########################################################################
19+
## PROTOC ##
20+
########################################################################
21+
22+
# Only set PROTOC_VER if it has an empty value.
23+
ifeq (,$(strip $(PROTOC_VER)))
24+
PROTOC_VER := 3.5.1
25+
endif
26+
27+
PROTOC_OS := $(shell uname -s)
28+
ifeq (Darwin,$(PROTOC_OS))
29+
PROTOC_OS := osx
30+
endif
31+
32+
PROTOC_ARCH := $(shell uname -m)
33+
ifeq (i386,$(PROTOC_ARCH))
34+
PROTOC_ARCH := x86_32
35+
endif
36+
37+
PROTOC := ./protoc
38+
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
39+
PROTOC_URL := https://github.com/google/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
40+
PROTOC_TMP_DIR := .protoc
41+
PROTOC_TMP_BIN := $(PROTOC_TMP_DIR)/bin/protoc
42+
43+
$(PROTOC):
44+
-mkdir -p "$(PROTOC_TMP_DIR)" && \
45+
curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \
46+
unzip "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" -d "$(PROTOC_TMP_DIR)" && \
47+
chmod 0755 "$(PROTOC_TMP_BIN)" && \
48+
cp -f "$(PROTOC_TMP_BIN)" "$@"
49+
stat "$@" > /dev/null 2>&1
50+
51+
52+
########################################################################
53+
## PROTOC-GEN-GO ##
54+
########################################################################
55+
56+
# This is the recipe for getting and installing the go plug-in
57+
# for protoc
58+
PROTOC_GEN_GO_PKG := github.com/golang/protobuf/protoc-gen-go
59+
PROTOC_GEN_GO := protoc-gen-go
60+
$(PROTOC_GEN_GO): PROTOBUF_PKG := $(dir $(PROTOC_GEN_GO_PKG))
61+
$(PROTOC_GEN_GO): PROTOBUF_VERSION := v1.2.0
62+
$(PROTOC_GEN_GO):
63+
mkdir -p $(dir $(GOPATH)/src/$(PROTOBUF_PKG))
64+
test -d $(GOPATH)/src/$(PROTOBUF_PKG)/.git || git clone https://$(PROTOBUF_PKG) $(GOPATH)/src/$(PROTOBUF_PKG)
65+
(cd $(GOPATH)/src/$(PROTOBUF_PKG) && \
66+
(test "$$(git describe --tags | head -1)" = "$(PROTOBUF_VERSION)" || \
67+
(git fetch && git checkout tags/$(PROTOBUF_VERSION))))
68+
(cd $(GOPATH)/src/$(PROTOBUF_PKG) && go get -v -d $$(go list -f '{{ .ImportPath }}' ./...)) && \
69+
go build -o "$@" $(PROTOC_GEN_GO_PKG)
70+
71+
72+
########################################################################
73+
## PATH ##
74+
########################################################################
75+
76+
# Update PATH with the current directory. This enables the protoc
77+
# binary to discover the protoc-gen-go binary, built inside this
78+
# directory.
79+
export PATH := $(shell pwd):$(PATH)
80+
81+
82+
########################################################################
83+
## BUILD ##
84+
########################################################################
85+
CSI_PROTO := ./csitest.proto
86+
CSI_PKG_ROOT := github.com/kubernetes-csi/csi-lib-utils/test/pkg/csi-spec
87+
CSI_PKG_SUB := $(shell cat $(CSI_PROTO) | sed -n -e 's/^package.\([^;]*\).v[0-9]\+;$$/\1/p'|tr '.' '/')
88+
CSI_BUILD := $(CSI_PKG_SUB)/.build
89+
CSI_GO := $(CSI_PKG_SUB)/csitest.pb.go
90+
CSI_A := csi.a
91+
CSI_GO_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/csitest.pb.go
92+
93+
# This recipe generates the go language bindings to a temp area.
94+
$(CSI_GO_TMP): HERE := $(shell pwd)
95+
$(CSI_GO_TMP): PTYPES_PKG := github.com/golang/protobuf/ptypes
96+
$(CSI_GO_TMP): GO_OUT := plugins=grpc
97+
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
98+
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG)/wrappers
99+
$(CSI_GO_TMP): GO_OUT := $(GO_OUT):"$(HERE)/$(CSI_BUILD)"
100+
$(CSI_GO_TMP): INCLUDE := -I$(GOPATH)/src -I$(HERE)/$(PROTOC_TMP_DIR)/include
101+
$(CSI_GO_TMP): $(CSI_PROTO) | $(PROTOC) $(PROTOC_GEN_GO)
102+
@mkdir -p "$(@D)"
103+
(cd "$(GOPATH)/src" && \
104+
$(HERE)/$(PROTOC) $(INCLUDE) --go_out=$(GO_OUT) "$(CSI_PKG_ROOT)/$(<F)")
105+
106+
# The temp language bindings are compared to the ones that are
107+
# versioned. If they are different then it means the language
108+
# bindings were not updated prior to being committed.
109+
$(CSI_GO): $(CSI_GO_TMP)
110+
ifeq (true,$(TRAVIS))
111+
diff "$@" "$?"
112+
else
113+
@mkdir -p "$(@D)"
114+
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
115+
endif
116+
117+
# This recipe builds the Go archive from the sources in three steps:
118+
#
119+
# 1. Go get any missing dependencies.
120+
# 2. Cache the packages.
121+
# 3. Build the archive file.
122+
$(CSI_A): $(CSI_GO)
123+
go get -v -d ./...
124+
go install ./$(CSI_PKG_SUB)
125+
go build -o "$@" ./$(CSI_PKG_SUB)
126+
127+
build: $(CSI_A)
128+
129+
clean:
130+
go clean -i ./...
131+
rm -rf "$(CSI_A)" "$(CSI_GO)" "$(CSI_BUILD)"
132+
133+
clobber: clean
134+
rm -fr "$(PROTOC)" "$(PROTOC_GEN_GO)" "$(CSI_PKG_SUB)" "$(PROTOC_TMP_DIR)"
135+
136+
.PHONY: clean clobber

test/pkg/csi-spec/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a *modified* version of the CSI 1.0.0 spec. It's only purpose is
2+
to test the stripping of secret fields.

0 commit comments

Comments
 (0)