Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

AbstractSession.storeCookie() support for run-time defined cookie names. #431

Merged
15 commits merged into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Imperative package will be documented in this file.

## Recent Changes

- Updated AbstractSession.storeCookie() to process cookie names not fully known at build-time.

## `4.7.5`

- Add allowableValues support for array
Expand Down
15 changes: 15 additions & 0 deletions packages/rest/__tests__/session/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ describe("Session tests", () => {
expect(session.ISession).toMatchSnapshot();
});

it("should store partial/dynamic cookie token requested", () => {
const cookieNameBase = "LtpaToken";
const cookieNameFull = cookieNameBase + "74133";
const cookieValue = "7KM/bf1sE4+4pE5mKgf+slWo9JO6laQF6OOi/POW0C+hRwscFOFjUijI2eWZrMY+jL4F9" +
"nl1ubUvcK0hPgWmKH4xCOf1EoNafu40XaiLoO8wZnCo/rHmP2/h7MzSJV1te8dP4VM6NFdQCruuxtcgddTiDXU8gYZERFTnvtYhUu" +
"vk1Nne8xwo++sDAmEFVwvJbyg6Z0zT1RAGPIXd6hx8YPNXydAifoQhqI9CaoyZNptByyx2H7uJ0vt0HTNqrdgZclOQkDNMm65ETpdo" +
"1u4U7Vd6HPoshHJEQo7p40T9jJfgv7PJ6Bxhp1dAqF5zEkqE";
const cookie: object = [cookieNameFull + "=" + cookieValue +
"; path=/; domain=ca23; Secure; HttpOnly; Expires=Tue, 19 Jan 2038 03:14:07 GMT;"];
const session = new Session({hostname: "localhost", type: "token", tokenType: cookieNameBase, user: "user", password: "password"});
session.storeCookie(cookie);
expect(session.ISession.tokenType).toBe(cookieNameFull);
expect(session.ISession.tokenValue).toBe(cookieValue);
});

it("should initialize with basic type and required input data", () => {
const session = new Session({hostname: "localhost", type: "basic", user: "ibmuser", password: "mypass"});
expect(session.ISession).toMatchSnapshot();
Expand Down
12 changes: 8 additions & 4 deletions packages/rest/src/session/AbstractSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ export abstract class AbstractSession {
const authArr = auth.split(";");
// see each field in the cookie, e/g. Path=/; Secure; HttpOnly; LtpaToken2=...
authArr.forEach((element: string) => {
// if we match requested token type, save it off for its length
if (element.indexOf(this.mISession.tokenType) === 0) {
// parse off token value, minus LtpaToken2= (as an example)
this.ISession.tokenValue = element.substr(this.ISession.tokenType.length + 1, element.length);
// if element begins with tokenType, extract full tokenType and tokenValue.
if (element.indexOf(this.ISession.tokenType) === 0) {
// parse off token value, splitting element at first "=".
const split = element.indexOf("=");
if (split >= 0) {
this.ISession.tokenType = element.substring(0, split);
this.ISession.tokenValue = element.substring(split + 1);
}
}
});
});
Expand Down