-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
remotereceivernotoken.go
86 lines (73 loc) · 2.34 KB
/
remotereceivernotoken.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieh.
See the License for the specific language governing permissions and
limitations under the License.
*/
package appapitoken
import (
"context"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/anypb"
commonv1 "github.com/dapr/dapr/pkg/proto/common/v1"
runtimev1 "github.com/dapr/dapr/pkg/proto/runtime/v1"
"github.com/dapr/dapr/tests/integration/framework"
"github.com/dapr/dapr/tests/integration/framework/process/daprd"
"github.com/dapr/dapr/tests/integration/framework/process/http/app"
"github.com/dapr/dapr/tests/integration/suite"
)
func init() {
suite.Register(new(remotereceivernotoken))
}
type remotereceivernotoken struct {
daprd1 *daprd.Daprd
daprd2 *daprd.Daprd
ch chan http.Header
}
func (n *remotereceivernotoken) Setup(t *testing.T) []framework.Option {
n.ch = make(chan http.Header, 1)
app := app.New(t,
app.WithHandlerFunc("/helloworld", func(w http.ResponseWriter, r *http.Request) {
n.ch <- r.Header
}),
)
n.daprd1 = daprd.New(t,
daprd.WithAppAPIToken(t, "abc"),
)
n.daprd2 = daprd.New(t,
daprd.WithAppPort(app.Port()),
)
return []framework.Option{
framework.WithProcesses(app, n.daprd1, n.daprd2),
}
}
func (n *remotereceivernotoken) Run(t *testing.T, ctx context.Context) {
n.daprd1.WaitUntilRunning(t, ctx)
n.daprd2.WaitUntilRunning(t, ctx)
dclient := n.daprd1.GRPCClient(t, ctx)
_, err := dclient.InvokeService(ctx, &runtimev1.InvokeServiceRequest{
Id: n.daprd2.AppID(),
Message: &commonv1.InvokeRequest{
Method: "helloworld",
Data: new(anypb.Any),
HttpExtension: &commonv1.HTTPExtension{Verb: commonv1.HTTPExtension_GET},
},
})
require.NoError(t, err)
select {
case header := <-n.ch:
require.Empty(t, header.Values("dapr-api-token"))
case <-time.After(5 * time.Second):
assert.Fail(t, "timed out waiting for header")
}
}