@@ -14,6 +14,7 @@ import (
14
14
"github.com/stretchr/testify/assert"
15
15
"github.com/stretchr/testify/require"
16
16
"google.golang.org/grpc/codes"
17
+ "google.golang.org/grpc/metadata"
17
18
"google.golang.org/grpc/status"
18
19
)
19
20
@@ -34,6 +35,7 @@ func TestV1(t *testing.T) {
34
35
for _ , tt := range []struct {
35
36
test string
36
37
plugin * fakeV1Plugin
38
+ ctx context.Context
37
39
payload string
38
40
responseErr error
39
41
expectAnyError bool
@@ -128,10 +130,32 @@ func TestV1(t *testing.T) {
128
130
expectMessage : "" ,
129
131
expectResult : resultWithSelectorsAndCanReattest ,
130
132
},
133
+ {
134
+ test : "attestation succeeds with original authority forwarded" ,
135
+ plugin : & fakeV1Plugin {challenges : challenges , agentID : agentID , selectorValues : selectorValues },
136
+ ctx : metadata .NewIncomingContext (
137
+ context .Background (),
138
+ metadata .New (map [string ]string {":authority" : "spire-server-xyz.spiffe.io:8081" }),
139
+ ),
140
+ payload : "without-challenge" ,
141
+ expectCode : codes .OK ,
142
+ expectMessage : "" ,
143
+ expectResult : & nodeattestor.AttestResult {
144
+ AgentID : agentID ,
145
+ Selectors : []* common.Selector {
146
+ {Type : "test" , Value : "value" },
147
+ {Type : "test" , Value : "spire-server-xyz.spiffe.io:8081" },
148
+ },
149
+ },
150
+ },
131
151
} {
132
152
t .Run (tt .test , func (t * testing.T ) {
133
153
nodeattestor := loadV1Plugin (t , tt .plugin )
134
- result , err := nodeattestor .Attest (context .Background (), []byte (tt .payload ),
154
+ ctx := tt .ctx
155
+ if ctx == nil {
156
+ ctx = context .Background ()
157
+ }
158
+ result , err := nodeattestor .Attest (ctx , []byte (tt .payload ),
135
159
func (ctx context.Context , challenge []byte ) ([]byte , error ) {
136
160
// echo the challenge back
137
161
return challenge , tt .responseErr
@@ -219,11 +243,17 @@ func (plugin *fakeV1Plugin) Attest(stream nodeattestorv1.NodeAttestor_AttestServ
219
243
}
220
244
}
221
245
246
+ selectorValues := plugin .selectorValues
247
+ originalAuthority := metadata .ValueFromIncomingContext (stream .Context (), nodeattestor .OriginalAuthorityKey )
248
+ if len (originalAuthority ) != 0 {
249
+ selectorValues = append (selectorValues , originalAuthority [0 ])
250
+ }
251
+
222
252
return stream .Send (& nodeattestorv1.AttestResponse {
223
253
Response : & nodeattestorv1.AttestResponse_AgentAttributes {
224
254
AgentAttributes : & nodeattestorv1.AgentAttributes {
225
255
SpiffeId : plugin .agentID ,
226
- SelectorValues : plugin . selectorValues ,
256
+ SelectorValues : selectorValues ,
227
257
CanReattest : plugin .canReattest ,
228
258
},
229
259
},
0 commit comments