diff --git a/features/Sdk.feature b/features/Sdk.feature index 19470d24..8fc236de 100644 --- a/features/Sdk.feature +++ b/features/Sdk.feature @@ -28,10 +28,10 @@ Feature: SDK commands Then The document "document-ricky" should exist And I should match stdout with "document-ricky" - # @mappings - # Scenario: Impersonate an user - # When I run the command "sdk:query" with: - # | arg | auth:getCurrentUser | | - # | flag | --as | gordon | - # Then I should match stdout with: - # | "_id": "gordon" | + @security + Scenario: Impersonate an user + Given an existing user "pandacrobate" + When I run the command "sdk:query auth:getCurrentUser" with flags: + | --as | "pandacrobate" | + Then I should match stdout with: + | "_id": "pandacrobate" | diff --git a/features/step_definitions/common/collection-steps.js b/features/step_definitions/common/collection-steps.js index b6969f4d..bb0f015f 100644 --- a/features/step_definitions/common/collection-steps.js +++ b/features/step_definitions/common/collection-steps.js @@ -24,6 +24,28 @@ Given( } ); +Given( + "an existing user {string}", + async function (userId) { + + try { + await this.sdk.security.getUser(userId); + } catch (error) { + await this.sdk.security.createUser(userId, { + content: { + profileIds: ['default'] + }, + credentials: { + local: { + username: userId, + password: 'password' + } + } + }); + } + } +); + Then("I list collections in index {string}", async function (index) { this.props.result = await this.sdk.collection.list(index); }); diff --git a/src/commands/app/scaffold.ts b/src/commands/app/scaffold.ts index 9067c11e..f39eec5b 100644 --- a/src/commands/app/scaffold.ts +++ b/src/commands/app/scaffold.ts @@ -62,7 +62,6 @@ export default class AppScaffold extends Kommand { } getRepo(flavor: string) { - console.log(flavor); switch (flavor) { case "generic": return "template-kuzzle-project"; diff --git a/src/commands/sdk/query.ts b/src/commands/sdk/query.ts index dac1bc41..d9c75523 100644 --- a/src/commands/sdk/query.ts +++ b/src/commands/sdk/query.ts @@ -114,7 +114,7 @@ Default fallback to API action static readStdin = true; - async runSafe() { + async runSafe(): Promise { const [controller, action] = this.args["controller:action"].split(":"); const requestArgs: any = {}; diff --git a/src/common.ts b/src/common.ts index 96b48412..70dafc37 100644 --- a/src/common.ts +++ b/src/common.ts @@ -188,11 +188,9 @@ export abstract class Kommand extends Command { process.exit(this.exitCode); } - - return this.exitCode; } - beforeConnect() { + async beforeConnect() { // will be called before connecting to Kuzzle } diff --git a/src/support/kuzzle.ts b/src/support/kuzzle.ts index 1553f004..2d4c62a7 100644 --- a/src/support/kuzzle.ts +++ b/src/support/kuzzle.ts @@ -114,8 +114,7 @@ export class KuzzleSDK { this.sdk.on("networkError", (error: any) => logger.logKo(error.message)); logger.logInfo( - `Connecting to ${this.protocol}${this.ssl ? "s" : ""}://${this.host}:${ - this.port + `Connecting to ${this.protocol}${this.ssl ? "s" : ""}://${this.host}:${this.port } ...` ); @@ -162,7 +161,7 @@ export class KuzzleSDK { apiKey = await this.security.createApiKey( userKuid, "Kourou impersonation token", - { expiresIn: "2h", refresh: false } as any + { expiresIn: "2h", refresh: "wait_for" } as any ); this.sdk.jwt = apiKey._source.token; @@ -214,9 +213,8 @@ export class KuzzleSDK { } // Construct the URL - const url = `${this.ssl ? "https" : "http"}://${this.host}:${ - this.port - }/_query`; + const url = `${this.ssl ? "https" : "http"}://${this.host}:${this.port + }/_query`; // Construct the request const body = JSON.stringify(request);