Skip to content
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
1 change: 1 addition & 0 deletions packages/browser-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
cypress/videos
cypress/screenshots
cypress/downloads
95 changes: 83 additions & 12 deletions packages/browser-tests/cypress/integration/auth/auth.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="cypress" />

const contextPath = process.env.QDB_HTTP_CONTEXT_WEB_CONSOLE || ""
const contextPath = process.env.QDB_HTTP_CONTEXT_WEB_CONSOLE || "";
const baseUrl = `http://localhost:9999${contextPath}`;

const interceptSettings = (payload) => {
Expand All @@ -12,10 +12,10 @@ const interceptSettings = (payload) => {
describe("OSS", () => {
before(() => {
interceptSettings({
"config": {
config: {
"release.type": "OSS",
"release.version": "1.2.3",
}
},
});
cy.visit(baseUrl);
});
Expand All @@ -29,7 +29,7 @@ describe("OSS", () => {
describe("Auth - UI", () => {
before(() => {
interceptSettings({
"config": {
config: {
"release.type": "EE",
"release.version": "1.2.3",
"acl.enabled": true,
Expand All @@ -40,7 +40,7 @@ describe("Auth - UI", () => {
"acl.oidc.token.endpoint": null,
"acl.oidc.pkce.required": null,
"acl.oidc.groups.encoded.in.token": false,
}
},
});
cy.visit(baseUrl);
});
Expand All @@ -52,11 +52,10 @@ describe("Auth - UI", () => {
});
});


describe("Auth - OIDC", () => {
before(() => {
interceptSettings({
"config": {
config: {
"release.type": "EE",
"release.version": "1.2.3",
"acl.enabled": true,
Expand All @@ -67,7 +66,7 @@ describe("Auth - OIDC", () => {
"acl.oidc.token.endpoint": "https://host:9999/token",
"acl.oidc.pkce.required": true,
"acl.oidc.groups.encoded.in.token": false,
}
},
});
cy.visit(baseUrl);
});
Expand All @@ -83,7 +82,7 @@ describe("Auth - OIDC", () => {
describe("Auth - Basic", () => {
before(() => {
interceptSettings({
"config": {
config: {
"release.type": "EE",
"release.version": "1.2.3",
"acl.enabled": true,
Expand All @@ -94,7 +93,7 @@ describe("Auth - Basic", () => {
"acl.oidc.token.endpoint": null,
"acl.oidc.pkce.required": null,
"acl.oidc.groups.encoded.in.token": false,
}
},
});
cy.visit(baseUrl);
});
Expand All @@ -108,7 +107,7 @@ describe("Auth - Basic", () => {
describe("Auth - Disabled", () => {
before(() => {
interceptSettings({
"config": {
config: {
"release.type": "EE",
"release.version": "1.2.3",
"acl.enabled": false,
Expand All @@ -119,7 +118,7 @@ describe("Auth - Disabled", () => {
"acl.oidc.token.endpoint": null,
"acl.oidc.pkce.required": null,
"acl.oidc.groups.encoded.in.token": false,
}
},
});
cy.visit(baseUrl);
});
Expand All @@ -129,3 +128,75 @@ describe("Auth - Disabled", () => {
cy.getEditor().should("be.visible");
});
});

describe("Auth - Session Parameter (OAuth)", () => {
describe("OAuth Login with session=true", () => {
beforeEach(() => {
interceptSettings({
config: {
"release.type": "EE",
"release.version": "1.2.3",
"acl.enabled": true,
"acl.basic.auth.realm.enabled": false,
"acl.oidc.enabled": true,
"acl.oidc.client.id": "test-client",
"acl.oidc.authorization.endpoint": "https://oauth.example.com/auth",
"acl.oidc.token.endpoint": "https://oauth.example.com/token",
"acl.oidc.pkce.required": true,
"acl.oidc.groups.encoded.in.token": false,
},
});
});

it("should call exec with session=true after OAuth token exchange", () => {
cy.intercept(
{
method: "GET",
url: `${baseUrl}/exec?query=select%202&session=true`,
},
(req) => {
expect(req.headers).to.have.property("authorization");
expect(req.headers.authorization).to.match(/^Bearer /);

req.reply({
statusCode: 200,
headers: {
"set-cookie": "qdb-session=oauth-session-id; Path=/; HttpOnly",
},
body: {
query: "select 2",
columns: [{ name: "column", type: "INT" }],
dataset: [[2]],
count: 1,
},
});
}
).as("oauthSessionStart");

cy.intercept(
{
method: "POST",
url: "https://oauth.example.com/token",
},
{
statusCode: 200,
body: {
access_token: "mock-access-token",
token_type: "Bearer",
expires_in: 3600,
},
}
).as("tokenExchange");

cy.visit(`${baseUrl}?code=test-auth-code&state=test-state`);
cy.wait("@settings");

cy.wait("@tokenExchange");
cy.wait("@oauthSessionStart").then((interception) => {
expect(interception.request.url).to.include("session=true");
expect(interception.request.url).to.include("select%202");
expect(interception.response.headers).to.have.property("set-cookie");
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
describe("download functionality", () => {
beforeEach(() => {
cy.loadConsoleWithAuth();
});

it("should show download button with results", () => {
// When
cy.typeQuery("select x from long_sequence(10)");
cy.runLine();

// Then
cy.getByDataHook("download-parquet-button").should("be.visible");
cy.getByDataHook("download-dropdown-button").should("be.visible");
cy.getByDataHook("download-csv-button").should("not.exist");

// When
cy.getByDataHook("download-dropdown-button").click();

// Then
cy.getByDataHook("download-csv-button").should("be.visible");
});

it("should trigger CSV download", () => {
const query = "select x from long_sequence(10)";

// Given
cy.intercept("GET", "**/exp?*", (req) => {
req.reply({
statusCode: 200,
body: null,
});
}).as("exportRequest");

// When
cy.typeQuery(query);
cy.runLine();
cy.getByDataHook("download-dropdown-button").click();
cy.getByDataHook("download-csv-button").click();

// Then
cy.wait("@exportRequest").then((interception) => {
expect(interception.request.url).to.include("fmt=csv");
expect(interception.request.url).to.include(
encodeURIComponent(query.replace(/\s+/g, " "))
);
});
});

it("should trigger Parquet download", () => {
const query = "select x from long_sequence(10)";

// Given
cy.intercept("GET", "**/exp?*", (req) => {
req.reply({
statusCode: 200,
body: null,
});
}).as("exportRequest");

// When
cy.typeQuery(query);
cy.runLine();
cy.getByDataHook("download-parquet-button").click();

// Then
cy.wait("@exportRequest").then((interception) => {
expect(interception.request.url).to.include("fmt=parquet");
expect(interception.request.url).to.include("rmode=nodelay");
expect(interception.request.url).to.include(
encodeURIComponent(query.replace(/\s+/g, " "))
);
});
});

it("should show error toast on bad request", () => {
// Given
cy.intercept("GET", "**/exp?*", (req) => {
const url = new URL(req.url);
url.searchParams.set("query", "badquery");
req.url = url.toString();
}).as("badExportRequest");

// When
cy.typeQuery("select x from long_sequence(5)");
cy.runLine();
cy.getByDataHook("download-dropdown-button").click();
cy.getByDataHook("download-csv-button").click();

// Then
cy.wait("@badExportRequest").then(() => {
cy.getByRole("alert").should(
"contain",
"An error occurred while downloading the file: table does not exist [table=badquery]"
);
});
});
});
87 changes: 87 additions & 0 deletions packages/browser-tests/cypress/integration/console/session.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/// <reference types="cypress" />

const contextPath = process.env.QDB_HTTP_CONTEXT_WEB_CONSOLE || "";
const baseUrl = `http://localhost:9999${contextPath}`;

describe("HTTP Session Management", () => {
it("should create session on login, maintain it across requests, and persist after page refresh", () => {
// Given
cy.intercept("GET", `${baseUrl}/exec?query=*&session=true`).as(
"sessionStart"
);

// When
cy.handleStorageAndVisit(baseUrl);
cy.loginWithUserAndPassword();

// Then
cy.wait("@sessionStart").then((interception) => {
expect(interception.request.url).to.include("session=true");
expect(interception.request.headers).to.have.property("authorization");
expect(interception.response.headers["set-cookie"]).to.exist;
});
cy.getEditor().should("be.visible");

// Given
cy.intercept("GET", /\/exec\?.*query=SELECT%201/).as("queryExec");

// When
cy.clearEditor();
cy.typeQuery("SELECT 1");
cy.clickRunIconInLine(1);

// Then
cy.wait("@queryExec").then((interception) => {
expect(interception.request.url).to.not.include("session=true");
expect(interception.request.url).to.not.include("session=false");
expect(interception.response.statusCode).to.equal(200);
});
cy.getGrid().should("be.visible");

// When
cy.handleStorageAndVisit(baseUrl, false);

// Then
cy.getEditor().should("be.visible");
cy.clearEditor();
cy.typeQuery("SELECT 2");
cy.clickRunIconInLine(1);
cy.getGrid().should("be.visible");
cy.getGridRow(0).should("contain", "2");
});

it("should destroy session on logout, clear local storage, and show login screen after refresh", () => {
// Given
cy.loadConsoleWithAuth();
cy.window().then((win) => {
const basicAuthHeader = win.localStorage.getItem("basic.auth.header");
expect(basicAuthHeader).to.not.be.null;
});
cy.intercept("GET", `${baseUrl}/exec?query=*&session=false`).as(
"sessionDestroy"
);

// When
cy.getByDataHook("button-logout").click();

// Then
cy.wait("@sessionDestroy").then((interception) => {
expect(interception.request.url).to.include("session=false");
expect(interception.request.url).to.include("select%202");
});
cy.getByDataHook("auth-login").should("be.visible");
cy.window().then((win) => {
const basicAuthHeader = win.localStorage.getItem("basic.auth.header");
const restToken = win.localStorage.getItem("rest.token");
expect(basicAuthHeader).to.be.null;
expect(restToken).to.be.null;
});

// When
cy.reload();

// Then
cy.getByDataHook("auth-login").should("be.visible");
cy.getEditor().should("not.exist");
});
});
2 changes: 1 addition & 1 deletion packages/browser-tests/questdb
Submodule questdb updated 532 files
3 changes: 2 additions & 1 deletion packages/web-console/serve-dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const server = http.createServer((req, res) => {
reqPathName.startsWith("/settings") ||
reqPathName.startsWith("/warnings") ||
reqPathName.startsWith("/chk") ||
reqPathName.startsWith("/imp")
reqPathName.startsWith("/imp") ||
reqPathName.startsWith("/exp")
) {
// proxy /exec requests to localhost:9000
const options = {
Expand Down
Loading