Skip to content

Commit

Permalink
Update Content-Type for login request (kiali#7253)
Browse files Browse the repository at this point in the history
* Update encoding for login requests
  • Loading branch information
josunect committed Apr 5, 2024
1 parent 353a3e5 commit 8cedfc9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
21 changes: 21 additions & 0 deletions frontend/cypress/integration/common/kiali_login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,24 @@ Then('user sees the {string} phrase displayed', (phrase: string) => {
cy.url().should('include', 'login');
}
});

Then('user fills in a valid password', () => {
if (auth_strategy === 'openshift') {
cy.log(`Log in as user with valid password: ${USERNAME}`);

cy.get('#inputUsername').clear().type(`${USERNAME}`);

cy.get('#inputPassword').type(`${PASSWD}`);
cy.get('button[type="submit"]').click();
}
if (auth_strategy === 'token') {
cy.exec('kubectl -n istio-system create token citest').then(result => {
cy.get('#token').type(result.stdout);
cy.get('button[type="submit"]').click();
});
}
});

Then('user sees the Overview page', () => {
cy.get('div[data-test="overview-app-health"]').should('exist');
});
4 changes: 4 additions & 0 deletions frontend/cypress/integration/featureFiles/kiali_login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ Feature: Kiali login
Scenario: Try to log in with an invalid password
And user fills in an invalid password
Then user sees the "Invalid login or password. Please try again." phrase displayed

Scenario: Try to log in with a valid password
And user fills in a valid password
Then user sees the Overview page
13 changes: 6 additions & 7 deletions frontend/src/services/Api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosError } from 'axios';
import axios, {AxiosError} from 'axios';
import { config } from '../config';
import { LoginSession } from '../store/Store';
import { App } from '../types/App';
Expand Down Expand Up @@ -74,12 +74,11 @@ const loginHeaders = config.login.headers;

/** Helpers to Requests */

const getHeaders = () => {
if (apiProxy) {
return { 'Content-Type': 'application/x-www-form-urlencoded' };
} else {
return { 'Content-Type': 'application/json', ...loginHeaders };
const getHeaders = (urlEncoded?: boolean) => {
if (apiProxy || urlEncoded) {
return { 'Content-Type': 'application/x-www-form-urlencoded', ...loginHeaders };
}
return { 'Content-Type': 'application/json', ...loginHeaders };
};

const basicAuth = (username: UserName, password: Password) => {
Expand Down Expand Up @@ -116,7 +115,7 @@ export const login = async (
return axios({
method: HTTP_VERBS.POST,
url: apiProxy ? `${apiProxy}/${urls.authenticate}` : urls.authenticate,
headers: getHeaders(),
headers: getHeaders(true),
auth: basicAuth(request.username, request.password),
data: params
});
Expand Down

0 comments on commit 8cedfc9

Please sign in to comment.