-
Notifications
You must be signed in to change notification settings - Fork 51
/
api_key_test.go
71 lines (67 loc) · 1.78 KB
/
api_key_test.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
package gokong
import (
"testing"
)
func Test_ApiKeyPassedViaHeader(t *testing.T) {
//apiRequest := &ApiRequest{
// Name: String("admin-api"),
// Uris: StringSlice([]string{"/admin-api"}),
// UpstreamUrl: String("http://localhost:8001"),
//}
//
//client := NewClient(NewDefaultConfig())
//createdApi, err := client.Apis().Create(apiRequest)
//
//assert.Nil(t, err)
//assert.NotNil(t, createdApi)
//
//consumerRequest := &ConsumerRequest{
// Username: "username-" + uuid.NewV4().String(),
// CustomId: "test-" + uuid.NewV4().String(),
//}
//
//createdConsumer, err := client.Consumers().Create(consumerRequest)
//
//assert.Nil(t, err)
//assert.NotNil(t, createdConsumer)
//
//pluginRequest := &PluginRequest{
// Name: "key-auth",
// ApiId: *createdApi.Id,
// Config: map[string]interface{}{
// "hide_credentials": true,
// },
//}
//
//createdPlugin, err := client.Plugins().Create(pluginRequest)
//
//assert.Nil(t, err)
//assert.NotNil(t, createdPlugin)
//
//c, err := client.Consumers().CreatePluginConfig(createdConsumer.Id, "key-auth", "")
//
//m := make(map[string]interface{})
//json.Unmarshal([]byte(c.Body), &m)
//
//kongApiAddress := os.Getenv(EnvKongApiHostAddress) + "/admin-api"
//unauthorisedClient := NewClient(&Config{HostAddress: kongApiAddress})
//
//api, err := unauthorisedClient.Apis().GetByName("admin-api")
//
//assert.NotNil(t, err)
//assert.Nil(t, api)
//
//authorisedClient := NewClient(&Config{HostAddress: kongApiAddress, ApiKey: m["key"].(string)})
//
//api, err = authorisedClient.Apis().GetByName("admin-api")
//assert.Nil(t, err)
//assert.NotNil(t, api)
//
//err = client.Plugins().DeleteById(createdPlugin.Id)
//
//assert.Nil(t, err)
//
//err = client.Apis().DeleteById(*createdApi.Id)
//
//assert.Nil(t, err)
}