From 930b3d4538f99d9937cc6fb38f1372c22ea189a4 Mon Sep 17 00:00:00 2001 From: "SPRINX0\\prochazka" Date: Fri, 27 Jun 2025 10:51:10 +0200 Subject: [PATCH] SYNC: cloud test - use test login --- e2e-tests/cypress/e2e/cloud.cy.js | 50 ++++++++++++++------------- packages/api/src/controllers/auth.js | 13 ++++++- packages/api/src/utility/cloudIntf.js | 17 +++++++++ packages/web/src/utility/api.ts | 11 ++++++ 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/e2e-tests/cypress/e2e/cloud.cy.js b/e2e-tests/cypress/e2e/cloud.cy.js index 835ac4b25..d5c25e50e 100644 --- a/e2e-tests/cypress/e2e/cloud.cy.js +++ b/e2e-tests/cypress/e2e/cloud.cy.js @@ -14,35 +14,37 @@ beforeEach(() => { describe('Cloud tests', () => { it('Private cloud', () => { - cy.testid('WidgetIconPanel_cloudAccount').click(); - - cy.origin('https://identity.dbgate.io', () => { - cy.contains('Sign in with GitHub').click(); + cy.window().then(win => { + win.__loginToCloudTest('dbgate.test@gmail.com'); }); - cy.origin('https://github.com', () => { - cy.get('#login_field').type('dbgatetest'); - cy.get('#password').type('Pwd2020Db'); - cy.get('input[type="submit"]').click(); - }); + // cy.testid('WidgetIconPanel_cloudAccount').click(); - cy.wait(3000); + // cy.origin('https://identity.dbgate.io', () => { + // cy.contains('Sign in with GitHub').click(); + // }); - cy.location('origin').then(origin => { - if (origin === 'https://github.com') { - // Still on github.com → an authorization step is waiting - cy.origin('https://github.com', () => { - // Try once, don't wait the full default timeout - cy.get('button[data-octo-click="oauth_application_authorization"]', { timeout: 500, log: false }).click(); // if the button exists it will be clicked - // if not, the short timeout elapses and we drop out - }); - } else { - // Already back on localhost – nothing to authorize - cy.log('OAuth redirect skipped the Authorize screen'); - } - }); + // cy.origin('https://github.com', () => { + // cy.get('#login_field').type('dbgatetest'); + // cy.get('#password').type('Pwd2020Db'); + // cy.get('input[type="submit"]').click(); + // }); - cy.themeshot('private-cloud-login'); + // cy.wait(3000); + + // cy.location('origin').then(origin => { + // if (origin === 'https://github.com') { + // // Still on github.com → an authorization step is waiting + // cy.origin('https://github.com', () => { + // // Try once, don't wait the full default timeout + // cy.get('button[data-octo-click="oauth_application_authorization"]', { timeout: 500, log: false }).click(); // if the button exists it will be clicked + // // if not, the short timeout elapses and we drop out + // }); + // } else { + // // Already back on localhost – nothing to authorize + // cy.log('OAuth redirect skipped the Authorize screen'); + // } + // }); cy.contains('Testing Connections').rightclick(); cy.contains('Administrate access').click(); diff --git a/packages/api/src/controllers/auth.js b/packages/api/src/controllers/auth.js index ca373363a..dd6953f77 100644 --- a/packages/api/src/controllers/auth.js +++ b/packages/api/src/controllers/auth.js @@ -13,7 +13,12 @@ const { } = require('../auth/authProvider'); const storage = require('./storage'); const { decryptPasswordString } = require('../utility/crypting'); -const { createDbGateIdentitySession, startCloudTokenChecking, readCloudTokenHolder } = require('../utility/cloudIntf'); +const { + createDbGateIdentitySession, + startCloudTokenChecking, + readCloudTokenHolder, + readCloudTestTokenHolder, +} = require('../utility/cloudIntf'); const socket = require('../utility/socket'); const logger = getLogger('auth'); @@ -154,5 +159,11 @@ module.exports = { return tokenHolder; }, + cloudTestLogin_meta: true, + async cloudTestLogin({ email }) { + const tokenHolder = await readCloudTestTokenHolder(email); + return tokenHolder; + }, + authMiddleware, }; diff --git a/packages/api/src/utility/cloudIntf.js b/packages/api/src/utility/cloudIntf.js index 9b4733fed..7fb4232c3 100644 --- a/packages/api/src/utility/cloudIntf.js +++ b/packages/api/src/utility/cloudIntf.js @@ -93,6 +93,22 @@ async function readCloudTokenHolder(sid) { return null; } +async function readCloudTestTokenHolder(email) { + const resp = await axios.default.post( + `${DBGATE_IDENTITY_URL}/api/test-token`, + { email }, + { + headers: { + ...getLicenseHttpHeaders(), + }, + } + ); + if (resp.data?.email) { + return resp.data; + } + return null; +} + async function loadCloudFiles() { try { const fileContent = await fs.readFile(path.join(datadir(), 'cloud-files.jsonl'), 'utf-8'); @@ -410,4 +426,5 @@ module.exports = { putCloudContent, removeCloudCachedConnection, readCloudTokenHolder, + readCloudTestTokenHolder, }; diff --git a/packages/web/src/utility/api.ts b/packages/web/src/utility/api.ts index 14ca14985..31a8e23bc 100644 --- a/packages/web/src/utility/api.ts +++ b/packages/web/src/utility/api.ts @@ -329,3 +329,14 @@ function disableApiLog() { window['enableApiLog'] = enableApiLog; window['disableApiLog'] = disableApiLog; + +window['__loginToCloudTest'] = async email => { + const tokenHolder = await apiCall('auth/cloud-test-login', { email }); + + if (tokenHolder) { + cloudSigninTokenHolder.set(tokenHolder); + selectedWidget.set('cloud-private'); + } else { + showSnackbarError('Login failed'); + } +};