Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: failiing tests #263

Merged
merged 2 commits into from
Jul 3, 2024
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
2 changes: 1 addition & 1 deletion bundle/bundle.js

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions lib/build/fetch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions lib/ts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,32 @@ export async function onUnauthorisedResponse(
});
return { result: "SESSION_EXPIRED" };
}
if (
postLockLSS.status !== preRequestLSS.status ||
(postLockLSS.status === "EXISTS" &&
preRequestLSS.status === "EXISTS" &&
postLockLSS.lastAccessTokenUpdate !== preRequestLSS.lastAccessTokenUpdate)
) {

const postLockSessionExists = postLockLSS.status === "EXISTS";
const preRequestSessionExists = preRequestLSS.status === "EXISTS";
const sessionStatusChanged = postLockLSS.status !== preRequestLSS.status;
const accessTokenTimestampChanged =
"lastAccessTokenUpdate" in postLockLSS &&
"lastAccessTokenUpdate" in preRequestLSS &&
postLockLSS.lastAccessTokenUpdate !== preRequestLSS.lastAccessTokenUpdate;

// If the session status has changed, we should return early and retry the request
// only if postLockLSS.status is "EXISTS".
if (sessionStatusChanged && postLockSessionExists) {
logDebugMessage(
"onUnauthorisedResponse: Retrying early because session status has changed and postLockLSS.status is EXISTS"
);
return { result: "RETRY" };
}

// If the session exists in both postLockLSS and preRequestLSS, we should return early
// and retry the request only if the access token timestamp has changed.
// This indicates that another process has already called this API and succeeded,
// so we don't need to call it again.
if (postLockSessionExists && preRequestSessionExists && accessTokenTimestampChanged) {
logDebugMessage(
"onUnauthorisedResponse: Retrying early because pre and post lastAccessTokenUpdate don't match"
);
// means that some other process has already called this API and succeeded. so we need to call it again
return { result: "RETRY" };
}

Expand Down
33 changes: 0 additions & 33 deletions test/axios.headers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,39 +437,6 @@ describe.skip("Axios AuthHttpRequest class tests header", function () {
}
});

it("test sameSite is none if using iframe axios", async function () {
await startST(3);
const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
try {
const page = await browser.newPage();
await page.goto(BASE_URL + "/index.html", { waitUntil: "load" });
await page.addScriptTag({ path: `./bundle/bundle.js`, type: "text/javascript" });
await page.evaluate(async () => {
let BASE_URL = "http://localhost.org:8080";
supertokens.addAxiosInterceptors(axios);
supertokens.init({
apiDomain: BASE_URL,
tokenTransferMethod: "header",
isInIframe: true
});
let userId = "testing-supertokens-website";
let loginResponse = await axios.post(`${BASE_URL}/login`, JSON.stringify({ userId }), {
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
});
});

let cookies = await page.cookies();
assert(cookies.length === 0);
} finally {
await browser.close();
}
});

it("test rid is there", async function () {
await startST(3);
const browser = await puppeteer.launch({
Expand Down
32 changes: 0 additions & 32 deletions test/axios.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,38 +509,6 @@ describe("Axios AuthHttpRequest class tests", function () {
}
});

it("test sameSite is none if using iframe axios", async function () {
await startST(3);
const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
try {
const page = await browser.newPage();
await page.goto(BASE_URL + "/index.html", { waitUntil: "load" });
await page.addScriptTag({ path: `./bundle/bundle.js`, type: "text/javascript" });
await page.evaluate(async () => {
let BASE_URL = "http://localhost.org:8080";
supertokens.addAxiosInterceptors(axios);
supertokens.init({
apiDomain: BASE_URL,
isInIframe: true
});
let userId = "testing-supertokens-website";
let loginResponse = await axios.post(`${BASE_URL}/login`, JSON.stringify({ userId }), {
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
});
});

let cookies = await page.cookies();
assert(cookies.length === 0);
} finally {
await browser.close();
}
});

it("test rid is there", async function () {
await startST(3);
const browser = await puppeteer.launch({
Expand Down
34 changes: 0 additions & 34 deletions test/fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,40 +494,6 @@ describe("Fetch AuthHttpRequest class tests", function () {
}
});

it("test sameSite is none if using iframe", async function () {
await startST(3);
const browser = await puppeteer.launch({
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
try {
const page = await browser.newPage();
await page.goto(BASE_URL + "/index.html", { waitUntil: "load" });
await page.addScriptTag({ path: `./bundle/bundle.js`, type: "text/javascript" });
await page.evaluate(async () => {
let BASE_URL = "http://localhost.org:8080";
supertokens.init({
apiDomain: BASE_URL,
isInIframe: true
});
let userId = "testing-supertokens-website";

await fetch(`${BASE_URL}/login`, {
method: "post",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({ userId })
});
});

let cookies = await page.cookies();
assert(cookies.length === 0);
} finally {
await browser.close();
}
});

it("test rid is there", async function () {
await startST(3);
const browser = await puppeteer.launch({
Expand Down
27 changes: 24 additions & 3 deletions test/interception.basic1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,25 @@ addTestCases((name, transferMethod, setupFunc, setupArgs = []) => {

it("test sameSite is none if using iframe", async function () {
await startST(3);

// NOTE: Using localhost:8080 as the base URL because browsers ignore
// SameSite=None, Secure: true cookies on HTTP non-localhost domains.

const BASE_URL = "http://localhost:8080";
await page.goto(BASE_URL + "/index.html", { waitUntil: "load" });
await page.addScriptTag({ path: `./bundle/bundle.js`, type: "text/javascript" });
await page.evaluate(BASE_URL => (window.BASE_URL = BASE_URL), BASE_URL);
await new Promise(r => setTimeout(r, 100));

await setup({
isInIframe: true
});

await page.evaluate(async () => {
const userId = "testing-supertokens-website";

await toTest({
url: `${BASE_URL}/login`,
url: `http://localhost:8080/login`,
method: "post",
headers: {
Accept: "application/json",
Expand All @@ -227,8 +238,18 @@ addTestCases((name, transferMethod, setupFunc, setupArgs = []) => {
});
});

const cookies = await page.cookies();
assert.strictEqual(cookies.length, 0);
let cookies = await page.cookies();

// Assert that all frontend cookies are sameSite=None and Secure: true
const frontendCookies =
transferMethod === "cookie"
? ["sAntiCsrf", "sFrontToken", "st-last-access-token-update"]
: ["sFrontToken", "st-last-access-token-update", "st-access-token", "st-refresh-token"];
frontendCookies.forEach(cookieName => {
const cookie = cookies.find(cookie => cookie.name === cookieName);
assert(cookie.sameSite === "None");
assert(cookie.secure === true);
});
});

it("test warnings when cookie writes are not successful", async function () {
Expand Down
Loading