Skip to content

Commit

Permalink
Merge pull request #213 from kuzzleio/fix/impersonate-test
Browse files Browse the repository at this point in the history
fix: impersonate test
  • Loading branch information
rolljee authored Dec 16, 2024
2 parents fb89301 + 09a166d commit 3d116de
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
14 changes: 7 additions & 7 deletions features/Sdk.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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" |
22 changes: 22 additions & 0 deletions features/step_definitions/common/collection-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
1 change: 0 additions & 1 deletion src/commands/app/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default class AppScaffold extends Kommand {
}

getRepo(flavor: string) {
console.log(flavor);
switch (flavor) {
case "generic":
return "template-kuzzle-project";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sdk/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Default fallback to API action

static readStdin = true;

async runSafe() {
async runSafe(): Promise<void> {
const [controller, action] = this.args["controller:action"].split(":");

const requestArgs: any = {};
Expand Down
4 changes: 1 addition & 3 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 4 additions & 6 deletions src/support/kuzzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
} ...`
);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d116de

Please sign in to comment.