Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cla-backend-go/users/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ func Configure(api *operations.ClaAPI, service Service, eventsService events.Ser
}

userModel, err := service.GetUser(params.UserID)
if err != nil {
if err != nil || userModel == nil {
if err == nil {
err = fmt.Errorf("user not found for user_id: %s", params.UserID)
}
log.WithFields(f).Warnf("error retrieving user for user_id: %s, error: %+v", params.UserID, err)
return users.NewGetUserCompatBadRequest().WithPayload(errorResponse(err))
}
Expand Down
108 changes: 108 additions & 0 deletions tests/functional/cypress/e2e/v3/docs.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import {
validate_200_Status,
getTokenKey,
getAPIBaseURL,
getXACLHeaders,
validate_expected_status,
} from '../../support/commands';

describe('To Validate & test Documentation APIs via API call (V3)', function () {
const claEndpoint = getAPIBaseURL('v3');
let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1);
const timeout = 180000;
const local = Cypress.env('LOCAL');

let bearerToken: string = null;
before(() => {
if (bearerToken == null) {
getTokenKey(bearerToken);
cy.window().then((win) => {
bearerToken = win.localStorage.getItem('bearerToken');
});
}
});

it('Get API Documentation - Record should return 200 Response', function () {
cy.request({
method: 'GET',
url: `${claEndpoint}api-docs`,
timeout: timeout,
failOnStatusCode: allowFail,
}).then((response) => {
validate_200_Status(response);
expect(response.body).to.not.be.null;
});
});

it('Get Swagger JSON - Record should return 200 Response', function () {
cy.request({
method: 'GET',
url: `${claEndpoint}swagger.json`,
timeout: timeout,
failOnStatusCode: allowFail,
}).then((response) => {
validate_200_Status(response);
expect(response.body).to.be.an('object');
expect(response.body).to.have.property('swagger');
expect(response.body).to.have.property('info');
expect(response.body).to.have.property('paths');
});
});

describe('Expected failures', () => {
it('Returns errors due to malformed requests for Documentation APIs', function () {
const cases: Array<{
title: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
url: string;
body?: any;
expectedStatus?: number;
expectedCode?: number;
expectedMessage?: string;
expectedMessageContains?: boolean;
}> = [
{
title: 'POST /api-docs (method not allowed)',
method: 'POST',
url: `${claEndpoint}api-docs`,
body: {},
expectedStatus: 405,
expectedCode: 405,
expectedMessage: 'method POST is not allowed, but [GET] are',
expectedMessageContains: true,
},
{
title: 'POST /swagger.json (method not allowed)',
method: 'POST',
url: `${claEndpoint}swagger.json`,
body: {},
expectedStatus: 405,
expectedCode: 405,
expectedMessage: 'method POST is not allowed, but [GET] are',
expectedMessageContains: true,
},
];

cy.wrap(cases).each((c: any) => {
return cy
.request({
method: c.method,
url: c.url,
body: c.body,
failOnStatusCode: false,
timeout,
})
.then((response) => {
cy.task('log', `Testing: ${c.title}`);
validate_expected_status(
response,
c.expectedStatus,
c.expectedCode,
c.expectedMessage,
c.expectedMessageContains,
);
});
});
});
});
});
85 changes: 85 additions & 0 deletions tests/functional/cypress/e2e/v3/health.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
validate_200_Status,
getTokenKey,
getAPIBaseURL,
getXACLHeaders,
validate_expected_status,
} from '../../support/commands';

describe('To Validate & test Health APIs via API call (V3)', function () {
const claEndpoint = getAPIBaseURL('v3');
let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1);
const timeout = 180000;
const local = Cypress.env('LOCAL');

let bearerToken: string = null;
before(() => {
if (bearerToken == null) {
getTokenKey(bearerToken);
cy.window().then((win) => {
bearerToken = win.localStorage.getItem('bearerToken');
});
}
});

it('Returns the Health of the application - Record should return 200 Response', function () {
cy.request({
method: 'GET',
url: `${claEndpoint}ops/health`,
timeout: timeout,
failOnStatusCode: allowFail,
}).then((response) => {
validate_200_Status(response);
expect(response.body).to.be.an('object');
expect(response.body).to.have.property('Status');
expect(response.body.Status).to.equal('healthy');
});
});

describe('Expected failures', () => {
it('Returns errors due to malformed requests for Health APIs', function () {
const cases: Array<{
title: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
url: string;
body?: any;
expectedStatus?: number;
expectedCode?: number;
expectedMessage?: string;
expectedMessageContains?: boolean;
}> = [
{
title: 'POST /ops/health (method not allowed)',
method: 'POST',
url: `${claEndpoint}ops/health`,
body: {},
expectedStatus: 405,
expectedCode: 405,
expectedMessage: 'method POST is not allowed, but [GET] are',
expectedMessageContains: true,
},
];

cy.wrap(cases).each((c: any) => {
return cy
.request({
method: c.method,
url: c.url,
body: c.body,
failOnStatusCode: false,
timeout,
})
.then((response) => {
cy.task('log', `Testing: ${c.title}`);
validate_expected_status(
response,
c.expectedStatus,
c.expectedCode,
c.expectedMessage,
c.expectedMessageContains,
);
});
});
});
});
});
125 changes: 125 additions & 0 deletions tests/functional/cypress/e2e/v3/organization.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import {
validate_200_Status,
validate_401_Status,
getTokenKey,
getAPIBaseURL,
getXACLHeaders,
validate_expected_status,
} from '../../support/commands';

describe('To Validate & test Organization APIs via API call (V3)', function () {
const claEndpoint = getAPIBaseURL('v3');
let allowFail: boolean = !(Cypress.env('ALLOW_FAIL') === 1);
const timeout = 180000;
const local = Cypress.env('LOCAL');

let bearerToken: string = null;
before(() => {
getTokenKey(bearerToken);
cy.window().then((win) => {
bearerToken = win.localStorage.getItem('bearerToken');
});
});

it('Search Organization by company name - Record should return 200 Response', function () {
const companyName = 'Linux Foundation';
cy.request({
method: 'GET',
url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}`,
timeout: timeout,
failOnStatusCode: allowFail,
}).then((response) => {
validate_200_Status(response);
expect(response.body).to.be.an('object');
if (response.body.list) {
expect(response.body.list).to.be.an('array');
}
});
});

it('Search Organization by website name - Record should return 200 Response', function () {
const websiteName = 'linuxfoundation.org';
cy.request({
method: 'GET',
url: `${claEndpoint}organization/search?websiteName=${encodeURIComponent(websiteName)}`,
timeout: timeout,
failOnStatusCode: allowFail,
}).then((response) => {
validate_200_Status(response);
expect(response.body).to.be.an('object');
if (response.body.list) {
expect(response.body.list).to.be.an('array');
}
});
});

it('Search Organization with both company name and website - Record should return 200 Response', function () {
const companyName = 'Linux Foundation';
const websiteName = 'linuxfoundation.org';
cy.request({
method: 'GET',
url: `${claEndpoint}organization/search?companyName=${encodeURIComponent(companyName)}&websiteName=${encodeURIComponent(websiteName)}`,
timeout: timeout,
failOnStatusCode: allowFail,
}).then((response) => {
validate_200_Status(response);
expect(response.body).to.be.an('object');
if (response.body.list) {
expect(response.body.list).to.be.an('array');
}
});
});

describe('Expected failures', () => {
it('Returns errors due to missing or malformed parameters for Organization APIs', function () {
const cases: Array<{
title: string;
method: 'GET';
url: string;
expectedStatus: number;
expectedCode?: number;
expectedMessage?: string;
expectedMessageContains?: boolean;
}> = [
{
title: 'GET /organization/search with neither companyName nor websiteName',
method: 'GET',
url: `${claEndpoint}organization/search`,
expectedStatus: 400,
expectedMessage: 'companyName or websiteName',
expectedMessageContains: true,
},
{
title: 'GET /organization/search with malformed websiteName',
method: 'GET',
url: `${claEndpoint}organization/search?websiteName=not-a-valid-url`,
expectedStatus: 422,
expectedMessage: 'websiteName in query should match',
expectedMessageContains: true,
},
];

cy.wrap(cases).each((c: any) => {
cy.task('log', `--> ${c.title} | ${c.method} ${c.url}`);
return cy
.request({
method: c.method,
url: c.url,
failOnStatusCode: false,
timeout,
})
.then((response) => {
return cy.logJson('response', response).then(() => {
validate_expected_status(
response,
c.expectedStatus,
c.expectedCode,
c.expectedMessage,
c.expectedMessageContains,
);
});
});
});
});
});
});
Empty file.
Loading
Loading