diff --git a/src/__tests__/cmd/qscloud/connection_test_cloud.test.js b/src/__tests__/cmd/qscloud/connection_test_cloud.test.js new file mode 100644 index 0000000..0dfbb21 --- /dev/null +++ b/src/__tests__/cmd/qscloud/connection_test_cloud.test.js @@ -0,0 +1,65 @@ +import { jest, test, expect, describe } from '@jest/globals'; +import { qscloudTestConnection } from '../../../lib/cmd/qscloud/testconnection.js'; + +const options = { + logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', + tenantHost: process.env.CTRLQ_TENANT_HOST || '', + authType: process.env.CTRLQ_AUTH_TYPE || 'apikey', + apikey: process.env.CTRLQ_API_KEY || '', +}; + +const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 120000; // 2 minute default timeout +console.log(`Jest timeout: ${defaultTestTimeout}`); +jest.setTimeout(defaultTestTimeout); + +// Connection test using JWT auth +describe('connection test (JWT auth)', () => { + test('Verify parameters', async () => { + expect(options.logLevel).not.toHaveLength(0); + expect(options.tenantHost).not.toHaveLength(0); + expect(options.authType).toBe('apikey'); + expect(options.apikey).not.toHaveLength(0); + + // Check if the API key is a valid JWT + try { + const decoded = JSON.parse(Buffer.from(options.apikey.split('.')[1], 'base64').toString('utf8')); + expect(decoded).toBeInstanceOf(Object); + + expect(decoded.aud).toBe('qlik.api'); + expect(decoded.iss).toBe('qlik.api/api-keys'); + + // JTI should be a UUID + expect(decoded.jti).not.toHaveLength(0); + expect(decoded.jti).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/); + + expect(decoded.sub).not.toHaveLength(0); + expect(decoded.subType).toBe('user'); + + expect(decoded.tenantId).not.toHaveLength(0); + } catch (error) { + expect(error).toBeInstanceOf(Error); + expect(error.message).toBe('Invalid API key'); + } + }); + + /** + * Do connection test + * Should succeed + */ + test('do connection test', async () => { + const result = await qscloudTestConnection(options); + + const decoded = JSON.parse(Buffer.from(options.apikey.split('.')[1], 'base64').toString('utf8')); + + // Result should be a JSON object + expect(result).toBeInstanceOf(Object); + expect(result.tenantId).toBe(decoded.tenantId); + + expect(result.id).not.toHaveLength(0); + expect(result.id).toBe(decoded.sub); + + expect(result.name).not.toHaveLength(0); + expect(result.email).not.toHaveLength(0); + expect(result.status).not.toHaveLength(0); + }); +}); diff --git a/src/__tests__/cmd/activity_custom_property_create_cert.test.js b/src/__tests__/cmd/qseow/activity_custom_property_create_cert.test.js similarity index 95% rename from src/__tests__/cmd/activity_custom_property_create_cert.test.js rename to src/__tests__/cmd/qseow/activity_custom_property_create_cert.test.js index 9df9a89..36eb7fc 100644 --- a/src/__tests__/cmd/activity_custom_property_create_cert.test.js +++ b/src/__tests__/cmd/qseow/activity_custom_property_create_cert.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { createUserActivityBucketsCustomProperty } from '../../lib/cmd/qseow/createuseractivitycp.js'; +import { createUserActivityBucketsCustomProperty } from '../../../lib/cmd/qseow/createuseractivitycp.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_cert.test.js b/src/__tests__/cmd/qseow/app_cert.test.js similarity index 97% rename from src/__tests__/cmd/app_cert.test.js rename to src/__tests__/cmd/qseow/app_cert.test.js index 61be8af..34c053d 100644 --- a/src/__tests__/cmd/app_cert.test.js +++ b/src/__tests__/cmd/qseow/app_cert.test.js @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import { jest, test, expect, describe } from '@jest/globals'; -import { getApps, getAppById } from '../../lib/util/qseow/app.js'; +import { getApps, getAppById } from '../../../lib/util/qseow/app.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_export_cert.test.js b/src/__tests__/cmd/qseow/app_export_cert.test.js similarity index 99% rename from src/__tests__/cmd/app_export_cert.test.js rename to src/__tests__/cmd/qseow/app_export_cert.test.js index fdf3e14..4b8878c 100644 --- a/src/__tests__/cmd/app_export_cert.test.js +++ b/src/__tests__/cmd/qseow/app_export_cert.test.js @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals'; import fs from 'node:fs'; import path from 'node:path'; -import { exportAppToFile } from '../../lib/cmd/qseow/exportapp.js'; +import { exportAppToFile } from '../../../lib/cmd/qseow/exportapp.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_export_jwt.test.js b/src/__tests__/cmd/qseow/app_export_jwt.test.js similarity index 99% rename from src/__tests__/cmd/app_export_jwt.test.js rename to src/__tests__/cmd/qseow/app_export_jwt.test.js index 8042a15..035f272 100644 --- a/src/__tests__/cmd/app_export_jwt.test.js +++ b/src/__tests__/cmd/qseow/app_export_jwt.test.js @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals'; import fs from 'node:fs'; import path from 'node:path'; -import { exportAppToFile } from '../../lib/cmd/qseow/exportapp.js'; +import { exportAppToFile } from '../../../lib/cmd/qseow/exportapp.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_import_cert.test.js b/src/__tests__/cmd/qseow/app_import_cert.test.js similarity index 95% rename from src/__tests__/cmd/app_import_cert.test.js rename to src/__tests__/cmd/qseow/app_import_cert.test.js index 4ba8f7d..15b70af 100644 --- a/src/__tests__/cmd/app_import_cert.test.js +++ b/src/__tests__/cmd/qseow/app_import_cert.test.js @@ -1,8 +1,8 @@ /* eslint-disable no-console */ import { jest, test, expect, describe } from '@jest/globals'; -import { importAppFromFile } from '../../lib/cmd/qseow/importapp.js'; -import { appExistById, deleteAppById } from '../../lib/util/qseow/app.js'; +import { importAppFromFile } from '../../../lib/cmd/qseow/importapp.js'; +import { appExistById, deleteAppById } from '../../../lib/util/qseow/app.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_import_jwt.test.js b/src/__tests__/cmd/qseow/app_import_jwt.test.js similarity index 94% rename from src/__tests__/cmd/app_import_jwt.test.js rename to src/__tests__/cmd/qseow/app_import_jwt.test.js index 83beeb3..449e567 100644 --- a/src/__tests__/cmd/app_import_jwt.test.js +++ b/src/__tests__/cmd/qseow/app_import_jwt.test.js @@ -1,8 +1,8 @@ /* eslint-disable no-console */ import { jest, test, expect, describe } from '@jest/globals'; -import { importAppFromFile } from '../../lib/cmd/qseow/importapp.js'; -import { appExistById, deleteAppById } from '../../lib/util/qseow/app.js'; +import { importAppFromFile } from '../../../lib/cmd/qseow/importapp.js'; +import { appExistById, deleteAppById } from '../../../lib/util/qseow/app.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_jwt.test.js b/src/__tests__/cmd/qseow/app_jwt.test.js similarity index 96% rename from src/__tests__/cmd/app_jwt.test.js rename to src/__tests__/cmd/qseow/app_jwt.test.js index c7f4bc2..f0559f2 100644 --- a/src/__tests__/cmd/app_jwt.test.js +++ b/src/__tests__/cmd/qseow/app_jwt.test.js @@ -1,9 +1,9 @@ /* eslint-disable no-console */ import { jest, test, expect, describe } from '@jest/globals'; -import { getApps, getAppById, appExistById, deleteAppById } from '../../lib/util/qseow/app.js'; -import { importAppFromFile } from '../../lib/cmd/qseow/importapp.js'; -import { sleep } from '../../globals.js'; +import { getApps, getAppById, appExistById, deleteAppById } from '../../../lib/util/qseow/app.js'; +import { importAppFromFile } from '../../../lib/cmd/qseow/importapp.js'; +import { sleep } from '../../../globals.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/app_scramble_cert.test.js b/src/__tests__/cmd/qseow/app_scramble_cert.test.js similarity index 99% rename from src/__tests__/cmd/app_scramble_cert.test.js rename to src/__tests__/cmd/qseow/app_scramble_cert.test.js index 3aad215..f101097 100644 --- a/src/__tests__/cmd/app_scramble_cert.test.js +++ b/src/__tests__/cmd/qseow/app_scramble_cert.test.js @@ -1,7 +1,7 @@ import { jest, test, expect, describe } from '@jest/globals'; import { validate as uuidValidate } from 'uuid'; -import { scrambleField } from '../../lib/cmd/qseow/scramblefield.js'; +import { scrambleField } from '../../../lib/cmd/qseow/scramblefield.js'; let options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/bookmark_get_cert.test.js b/src/__tests__/cmd/qseow/bookmark_get_cert.test.js similarity index 99% rename from src/__tests__/cmd/bookmark_get_cert.test.js rename to src/__tests__/cmd/qseow/bookmark_get_cert.test.js index 896d5f3..4ffe2e8 100644 --- a/src/__tests__/cmd/bookmark_get_cert.test.js +++ b/src/__tests__/cmd/qseow/bookmark_get_cert.test.js @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import { jest, test, expect, describe } from '@jest/globals'; -import { getBookmark } from '../../lib/cmd/qseow/getbookmark.js'; +import { getBookmark } from '../../../lib/cmd/qseow/getbookmark.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/bookmark_get_jwt.test.js b/src/__tests__/cmd/qseow/bookmark_get_jwt.test.js similarity index 98% rename from src/__tests__/cmd/bookmark_get_jwt.test.js rename to src/__tests__/cmd/qseow/bookmark_get_jwt.test.js index 027cf10..4519823 100644 --- a/src/__tests__/cmd/bookmark_get_jwt.test.js +++ b/src/__tests__/cmd/qseow/bookmark_get_jwt.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { getBookmark } from '../../lib/cmd/qseow/getbookmark.js'; +import { getBookmark } from '../../../lib/cmd/qseow/getbookmark.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/connection_test_cert.test.js b/src/__tests__/cmd/qseow/connection_test_cert.test.js similarity index 96% rename from src/__tests__/cmd/connection_test_cert.test.js rename to src/__tests__/cmd/qseow/connection_test_cert.test.js index 1c4baca..fe43c9d 100644 --- a/src/__tests__/cmd/connection_test_cert.test.js +++ b/src/__tests__/cmd/qseow/connection_test_cert.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { testConnection } from '../../lib/cmd/qseow/testconnection.js'; +import { testConnection } from '../../../lib/cmd/qseow/testconnection.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/connection_test_jwt.test.js b/src/__tests__/cmd/qseow/connection_test_jwt.test.js similarity index 96% rename from src/__tests__/cmd/connection_test_jwt.test.js rename to src/__tests__/cmd/qseow/connection_test_jwt.test.js index dc11d6f..7599c38 100644 --- a/src/__tests__/cmd/connection_test_jwt.test.js +++ b/src/__tests__/cmd/qseow/connection_test_jwt.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { testConnection } from '../../lib/cmd/qseow/testconnection.js'; +import { testConnection } from '../../../lib/cmd/qseow/testconnection.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/script_get_cert.test.js b/src/__tests__/cmd/qseow/script_get_cert.test.js similarity index 96% rename from src/__tests__/cmd/script_get_cert.test.js rename to src/__tests__/cmd/qseow/script_get_cert.test.js index 1597fdd..917c86b 100644 --- a/src/__tests__/cmd/script_get_cert.test.js +++ b/src/__tests__/cmd/qseow/script_get_cert.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { getScript } from '../../lib/cmd/qseow/getscript.js'; +import { getScript } from '../../../lib/cmd/qseow/getscript.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/script_get_jwt.test.js b/src/__tests__/cmd/qseow/script_get_jwt.test.js similarity index 96% rename from src/__tests__/cmd/script_get_jwt.test.js rename to src/__tests__/cmd/qseow/script_get_jwt.test.js index f7ced91..0fb22d3 100644 --- a/src/__tests__/cmd/script_get_jwt.test.js +++ b/src/__tests__/cmd/qseow/script_get_jwt.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { getScript } from '../../lib/cmd/qseow/getscript.js'; +import { getScript } from '../../../lib/cmd/qseow/getscript.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_cert.test.js b/src/__tests__/cmd/qseow/task_cert.test.js similarity index 99% rename from src/__tests__/cmd/task_cert.test.js rename to src/__tests__/cmd/qseow/task_cert.test.js index 9842641..b33311b 100644 --- a/src/__tests__/cmd/task_cert.test.js +++ b/src/__tests__/cmd/qseow/task_cert.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { taskExistById, getTaskByName, getTaskById } from '../../lib/util/qseow/task.js'; +import { taskExistById, getTaskByName, getTaskById } from '../../../lib/util/qseow/task.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_custom_property_set_cert.test.js b/src/__tests__/cmd/qseow/task_custom_property_set_cert.test.js similarity index 96% rename from src/__tests__/cmd/task_custom_property_set_cert.test.js rename to src/__tests__/cmd/qseow/task_custom_property_set_cert.test.js index 2cee835..5c19e10 100644 --- a/src/__tests__/cmd/task_custom_property_set_cert.test.js +++ b/src/__tests__/cmd/qseow/task_custom_property_set_cert.test.js @@ -1,7 +1,7 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { setTaskCustomProperty } from '../../lib/cmd/qseow/settaskcp.js'; -import { getTaskById } from '../../lib/util/qseow/task.js'; +import { setTaskCustomProperty } from '../../../lib/cmd/qseow/settaskcp.js'; +import { getTaskById } from '../../../lib/util/qseow/task.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_custom_property_set_jwt.test.js b/src/__tests__/cmd/qseow/task_custom_property_set_jwt.test.js similarity index 96% rename from src/__tests__/cmd/task_custom_property_set_jwt.test.js rename to src/__tests__/cmd/qseow/task_custom_property_set_jwt.test.js index 431c83b..8aa2dc7 100644 --- a/src/__tests__/cmd/task_custom_property_set_jwt.test.js +++ b/src/__tests__/cmd/qseow/task_custom_property_set_jwt.test.js @@ -1,7 +1,7 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { setTaskCustomProperty } from '../../lib/cmd/qseow/settaskcp.js'; -import { getTaskById } from '../../lib/util/qseow/task.js'; +import { setTaskCustomProperty } from '../../../lib/cmd/qseow/settaskcp.js'; +import { getTaskById } from '../../../lib/util/qseow/task.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_get_cert.test.js b/src/__tests__/cmd/qseow/task_get_cert.test.js similarity index 99% rename from src/__tests__/cmd/task_get_cert.test.js rename to src/__tests__/cmd/qseow/task_get_cert.test.js index c481e26..8e3b791 100644 --- a/src/__tests__/cmd/task_get_cert.test.js +++ b/src/__tests__/cmd/qseow/task_get_cert.test.js @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals'; import fs from 'node:fs'; import path from 'node:path'; -import { getTask } from '../../lib/cmd/qseow/gettask.js'; +import { getTask } from '../../../lib/cmd/qseow/gettask.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_get_jwt.test.js b/src/__tests__/cmd/qseow/task_get_jwt.test.js similarity index 99% rename from src/__tests__/cmd/task_get_jwt.test.js rename to src/__tests__/cmd/qseow/task_get_jwt.test.js index a01afc9..6491a41 100644 --- a/src/__tests__/cmd/task_get_jwt.test.js +++ b/src/__tests__/cmd/qseow/task_get_jwt.test.js @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals'; import fs from 'node:fs'; import path from 'node:path'; -import { getTask } from '../../lib/cmd/qseow/gettask.js'; +import { getTask } from '../../../lib/cmd/qseow/gettask.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_import_cert.test.js b/src/__tests__/cmd/qseow/task_import_cert.test.js similarity index 97% rename from src/__tests__/cmd/task_import_cert.test.js rename to src/__tests__/cmd/qseow/task_import_cert.test.js index 758fcc2..d92694f 100644 --- a/src/__tests__/cmd/task_import_cert.test.js +++ b/src/__tests__/cmd/qseow/task_import_cert.test.js @@ -1,8 +1,8 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { importTaskFromFile } from '../../lib/cmd/qseow/importtask.js'; -import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../lib/util/qseow/task.js'; -import { mapTaskType } from '../../lib/util/qseow/lookups.js'; +import { importTaskFromFile } from '../../../lib/cmd/qseow/importtask.js'; +import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../../lib/util/qseow/task.js'; +import { mapTaskType } from '../../../lib/util/qseow/lookups.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_import_jwt.test.js b/src/__tests__/cmd/qseow/task_import_jwt.test.js similarity index 97% rename from src/__tests__/cmd/task_import_jwt.test.js rename to src/__tests__/cmd/qseow/task_import_jwt.test.js index 4174cd6..6b6d2f1 100644 --- a/src/__tests__/cmd/task_import_jwt.test.js +++ b/src/__tests__/cmd/qseow/task_import_jwt.test.js @@ -1,8 +1,8 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { importTaskFromFile } from '../../lib/cmd/qseow/importtask.js'; -import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../lib/util/qseow/task.js'; -import { mapTaskType } from '../../lib/util/qseow/lookups.js'; +import { importTaskFromFile } from '../../../lib/cmd/qseow/importtask.js'; +import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../../lib/util/qseow/task.js'; +import { mapTaskType } from '../../../lib/util/qseow/lookups.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info', diff --git a/src/__tests__/cmd/task_jwt.test.js b/src/__tests__/cmd/qseow/task_jwt.test.js similarity index 99% rename from src/__tests__/cmd/task_jwt.test.js rename to src/__tests__/cmd/qseow/task_jwt.test.js index f48da47..014343e 100644 --- a/src/__tests__/cmd/task_jwt.test.js +++ b/src/__tests__/cmd/qseow/task_jwt.test.js @@ -1,6 +1,6 @@ import { jest, test, expect, describe } from '@jest/globals'; -import { taskExistById, getTaskByName, getTaskById } from '../../lib/util/qseow/task.js'; +import { taskExistById, getTaskByName, getTaskById } from '../../../lib/util/qseow/task.js'; const options = { logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',