Skip to content

Commit

Permalink
[ftr] print response body for API key creation failure (#195379)
Browse files Browse the repository at this point in the history
## Summary

We are currently investigating test failures against ESS deployment:
Failed to create API key for user `admin` role

```
[00:00:00]         └-> "before all" hook in "Burn rate rule"
[00:00:00]           │ debg new cloud SAML authentication with 'admin' role
[00:00:00]           │ debg Requesting url (redacted): [https://bk-stateful-ftr-16-2c9ee40b2d03.kb.eu-west-1.aws.qa.cld.elstc.co/api/status]
[00:00:00]           │ info Reading cloud user credentials from /root/.qaf/data/git/kibana/.ftr/role_users.json
[00:00:04]           └- ✖ fail: apis Slo - Burn rate rule Burn rate rule "before all" hook in "Burn rate rule"
[00:00:04]           │      Error: expected 400 to equal 200
[00:00:04]           │       at Assertion.assert (expect.js:100:11)
[00:00:04]           │       at Assertion.apply (expect.js:227:8)
[00:00:04]           │       at Assertion.be (expect.js:69:22)
[00:00:04]           │       at Object.createM2mApiKeyWithRoleScope (saml_auth_provider.ts:113:25)
[00:00:04]           │       at processTicksAndRejections (node:internal/process/task_queues:95:5)
[00:00:04]           │       at Context. (burn_rate_rule.ts:40:24)
[00:00:04]           │       at Object.apply (wrap_function.js:74:16)
```

Currently we get only status code and it doesn't tell much about the
issue. This PR will print response body + status code

(cherry picked from commit 0c5c712)
  • Loading branch information
dmlemeshko committed Oct 8, 2024
1 parent a2ed51e commit eef7e5a
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function SamlAuthProvider({ getService }: FtrProviderContext) {
};
}

const { body, status } = await supertestWithoutAuth
const response = await supertestWithoutAuth
.post('/internal/security/api_key')
.set(INTERNAL_REQUEST_HEADERS)
.set(adminCookieHeader)
Expand All @@ -110,9 +110,14 @@ export function SamlAuthProvider({ getService }: FtrProviderContext) {
metadata: {},
role_descriptors: roleDescriptors,
});
expect(status).to.be(200);

const apiKey = body;
if (response.status !== 200) {
throw new Error(
`Failed to create API key for '${role}' role with response text: ${response.text}`
);
}

const apiKey = response.body;
const apiKeyHeader = { Authorization: 'ApiKey ' + apiKey.encoded };

log.debug(`Created api key for role: [${role}]`);
Expand Down

0 comments on commit eef7e5a

Please sign in to comment.