-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add unit test for
qscloud connection-test
command
- Loading branch information
1 parent
e78fabc
commit 5e53a96
Showing
23 changed files
with
97 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...ivity_custom_property_create_cert.test.js → ...ivity_custom_property_create_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/app_cert.test.js → src/__tests__/cmd/qseow/app_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/__tests__/cmd/app_import_cert.test.js → ...tests__/cmd/qseow/app_import_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/__tests__/cmd/app_import_jwt.test.js → ..._tests__/cmd/qseow/app_import_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/__tests__/cmd/app_jwt.test.js → src/__tests__/cmd/qseow/app_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/app_scramble_cert.test.js → ...sts__/cmd/qseow/app_scramble_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/bookmark_get_cert.test.js → ...sts__/cmd/qseow/bookmark_get_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/bookmark_get_jwt.test.js → ...ests__/cmd/qseow/bookmark_get_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
..._tests__/cmd/connection_test_cert.test.js → ...__/cmd/qseow/connection_test_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...__tests__/cmd/connection_test_jwt.test.js → ...s__/cmd/qseow/connection_test_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/script_get_cert.test.js → ...tests__/cmd/qseow/script_get_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/script_get_jwt.test.js → ..._tests__/cmd/qseow/script_get_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/task_cert.test.js → src/__tests__/cmd/qseow/task_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...cmd/task_custom_property_set_cert.test.js → ...eow/task_custom_property_set_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../cmd/task_custom_property_set_jwt.test.js → ...seow/task_custom_property_set_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/__tests__/cmd/task_import_cert.test.js → ...ests__/cmd/qseow/task_import_cert.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/__tests__/cmd/task_import_jwt.test.js → ...tests__/cmd/qseow/task_import_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__tests__/cmd/task_jwt.test.js → src/__tests__/cmd/qseow/task_jwt.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters