Skip to content

Commit a6c0b92

Browse files
Add E2E Cypress negative cases tests for version.cy.ts
Signed-off-by: Lukasz Gryglicki <[email protected]> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent a1d15ed commit a6c0b92

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

tests/functional/cypress/e2e/v4/touch

Whitespace-only changes.

tests/functional/cypress/e2e/v4/version.cy.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import {
44
getTokenKey,
55
getAPIBaseURL,
66
getXACLHeader,
7+
validate_expected_status,
78
} from '../../support/commands';
89

910
describe('To Validate & check cla version via API call', function () {
1011
//Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/version
1112
const claEndpoint = getAPIBaseURL('v4');
1213
let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1);
14+
const timeout = 60000;
15+
const local = Cypress.env('LOCAL');
1316

1417
let bearerToken: string = null;
1518
before(() => {
@@ -37,4 +40,120 @@ describe('To Validate & check cla version via API call', function () {
3740
validateApiResponse('version/getVersion.json', response);
3841
});
3942
});
43+
44+
it('Version endpoint works without authentication (no token required)', function () {
45+
cy.request({
46+
method: 'GET',
47+
url: `${claEndpoint}ops/version`,
48+
timeout: 180000,
49+
failOnStatusCode: allowFail,
50+
headers: getXACLHeader(),
51+
// No auth - version endpoint is public
52+
}).then((response) => {
53+
validate_200_Status(response);
54+
//To validate schema of response
55+
validateApiResponse('version/getVersion.json', response);
56+
});
57+
});
58+
59+
// ========================= Expected failures (version) =========================
60+
describe('Expected failures', () => {
61+
it('Returns errors due to malformed requests for Version APIs', function () {
62+
const defaultHeaders = getXACLHeader();
63+
64+
const cases: Array<{
65+
title: string;
66+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
67+
url: string;
68+
body?: any;
69+
headers?: any;
70+
// when running locally
71+
expectedStatusLocal?: number;
72+
expectedCodeLocal?: number;
73+
expectedMessageLocal?: string;
74+
expectedMessageContainsLocal?: boolean;
75+
// when running against dev via ACS & API-gw
76+
expectedStatusRemote?: number;
77+
expectedCodeRemote?: number;
78+
expectedMessageRemote?: string;
79+
expectedMessageContainsRemote?: boolean;
80+
}> = [
81+
{
82+
title: 'POST /ops/version (method not allowed)',
83+
method: 'POST',
84+
url: `${claEndpoint}ops/version`,
85+
body: {},
86+
expectedStatusLocal: 405,
87+
expectedMessageLocal: 'method POST is not allowed, but [GET] are',
88+
expectedMessageContainsLocal: true,
89+
expectedStatusRemote: 405,
90+
expectedMessageRemote: 'method POST is not allowed, but [GET] are',
91+
expectedMessageContainsRemote: true,
92+
},
93+
{
94+
title: 'PUT /ops/version (method not allowed)',
95+
method: 'PUT',
96+
url: `${claEndpoint}ops/version`,
97+
body: {},
98+
expectedStatusLocal: 405,
99+
expectedMessageLocal: 'method PUT is not allowed, but [GET] are',
100+
expectedMessageContainsLocal: true,
101+
expectedStatusRemote: 405,
102+
expectedMessageRemote: 'method PUT is not allowed, but [GET] are',
103+
expectedMessageContainsRemote: true,
104+
},
105+
{
106+
title: 'DELETE /ops/version (method not allowed)',
107+
method: 'DELETE',
108+
url: `${claEndpoint}ops/version`,
109+
expectedStatusLocal: 405,
110+
expectedMessageLocal: 'method DELETE is not allowed, but [GET] are',
111+
expectedMessageContainsLocal: true,
112+
expectedStatusRemote: 405,
113+
expectedMessageRemote: 'method DELETE is not allowed, but [GET] are',
114+
expectedMessageContainsRemote: true,
115+
},
116+
{
117+
title: 'GET /ops/version/invalid-path (not found)',
118+
method: 'GET',
119+
url: `${claEndpoint}ops/version/invalid-path`,
120+
expectedStatusLocal: 404,
121+
expectedMessageLocal: 'path /v4/ops/version/invalid-path was not found',
122+
expectedMessageContainsLocal: true,
123+
expectedStatusRemote: 404,
124+
expectedMessageRemote: 'path /v4/ops/version/invalid-path was not found',
125+
expectedMessageContainsRemote: true,
126+
},
127+
];
128+
129+
cy.wrap(cases).each((c: any) => {
130+
return cy
131+
.request({
132+
method: c.method,
133+
url: c.url,
134+
body: c.body,
135+
headers: c.headers || defaultHeaders,
136+
failOnStatusCode: false,
137+
timeout,
138+
})
139+
.then((response) => {
140+
cy.task('log', `Testing: ${c.title}`);
141+
142+
const es = local
143+
? (c.expectedStatusLocal ?? c.expectedStatus)
144+
: (c.expectedStatusRemote ?? c.expectedStatus);
145+
const ec = local ? (c.expectedCodeLocal ?? c.expectedCode) : (c.expectedCodeRemote ?? c.expectedCode);
146+
const em = local
147+
? (c.expectedMessageLocal ?? c.expectedMessage)
148+
: (c.expectedMessageRemote ?? c.expectedMessage);
149+
const emc = local
150+
? (c.expectedMessageContainsLocal ?? c.expectedMessageContains)
151+
: (c.expectedMessageContainsRemote ?? c.expectedMessageContains);
152+
153+
cy.task('log', ` --> expected ${es}, ${ec}, '${em}' (contains? ${emc})`);
154+
validate_expected_status(response, es, ec, em, emc);
155+
});
156+
});
157+
});
158+
});
40159
});

0 commit comments

Comments
 (0)