forked from oasdiff/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-api-security-updated_test.go
183 lines (165 loc) · 7 KB
/
check-api-security-updated_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
)
// CL: Adding a new global security to the API
func TestAPIGlobalSecurityyAdded(t *testing.T) {
s1, err := open("../data/checker/api_security_global_added_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_global_added_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-added",
Text: "the security scheme 'petstore_auth' was added to the API",
Comment: "",
Level: checker.INFO,
Source: "",
}, errs[0])
}
// CL: Removing a global security from the API
func TestAPIGlobalSecurityyDeleted(t *testing.T) {
s1, err := open("../data/checker/api_security_global_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_global_added_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-removed",
Text: "the security scheme 'petstore_auth' was removed from the API",
Comment: "",
Level: checker.INFO,
Source: "",
}, errs[0])
}
// CL: Removing a security scope from an API global security
func TestAPIGlobalSecurityScopeRemoved(t *testing.T) {
s1, err := open("../data/checker/api_security_global_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_global_added_revision.yaml")
require.NoError(t, err)
s2.Spec.Security[0]["petstore_auth"] = s2.Spec.Security[0]["petstore_auth"][:1]
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-scope-removed",
Text: "the security scope 'read:pets' was removed from the global security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Source: "",
}, errs[0])
}
// CL: Adding a security scope from an API global security
func TestAPIGlobalSecurityScopeAdded(t *testing.T) {
s1, err := open("../data/checker/api_security_global_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_global_added_revision.yaml")
require.NoError(t, err)
s1.Spec.Security[0]["petstore_auth"] = s2.Spec.Security[0]["petstore_auth"][:1]
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.SecurityChange{
Id: "api-global-security-scope-added",
Text: "the security scope 'read:pets' was added to the global security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Source: "",
}, errs[0])
}
// CL: Adding a new security to the API endpoint
func TestAPISecurityAdded(t *testing.T) {
s1, err := open("../data/checker/api_security_added_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_added_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-added",
Text: "the endpoint scheme security 'petstore_auth' was added to the API",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/subscribe",
Source: "../data/checker/api_security_added_revision.yaml",
OperationId: "",
}, errs[0])
}
// CL: Removing a new security to the API endpoint
func TestAPISecurityDeleted(t *testing.T) {
s1, err := open("../data/checker/api_security_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_added_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-removed",
Text: "the endpoint scheme security 'petstore_auth' was removed from the API",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/subscribe",
Source: "../data/checker/api_security_added_base.yaml",
OperationId: "",
}, errs[0])
}
// CL: Removing a security scope from an API endpoint security
func TestAPISecurityScopeRemoved(t *testing.T) {
s1, err := open("../data/checker/api_security_updated_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_updated_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-scope-removed",
Text: "the security scope 'read:pets' was removed from the endpoint's security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/subscribe",
Source: "../data/checker/api_security_updated_revision.yaml",
OperationId: "",
}, errs[0])
}
// CL: Adding a security scope to an API endpoint security
func TestAPISecurityScopeAdded(t *testing.T) {
s1, err := open("../data/checker/api_security_updated_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/api_security_updated_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: "api-security-scope-added",
Text: "the security scope 'read:pets' was added to the endpoint's security scheme 'petstore_auth'",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/subscribe",
Source: "../data/checker/api_security_updated_base.yaml",
OperationId: "",
}, errs[0])
}