Skip to content

PIN-6745 - Fix get producer keychain keys 500 #1838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api-clients/open-api/authorizationApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Keys"
$ref: "#/components/schemas/Key"
"400":
description: Bad Request
content:
Expand Down
30 changes: 15 additions & 15 deletions packages/authorization-process/src/routers/AuthorizationRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,19 +771,16 @@ const authorizationRouter = (
try {
validateAuthorization(ctx, [ADMIN_ROLE, SECURITY_ROLE]);

const producerKeychain =
await authorizationService.createProducerKeychainKey(
{
producerKeychainId: unsafeBrandId(req.params.producerKeychainId),
keySeed: req.body,
},
ctx
);
return res.status(200).send(
authorizationApi.Keys.parse({
keys: producerKeychain.keys.map(keyToApiKey),
})
const key = await authorizationService.createProducerKeychainKey(
{
producerKeychainId: unsafeBrandId(req.params.producerKeychainId),
keySeed: req.body,
},
ctx
);
return res
.status(200)
.send(authorizationApi.Key.parse(keyToApiKey(key)));
} catch (error) {
const errorRes = makeApiProblem(
error,
Expand Down Expand Up @@ -812,9 +809,12 @@ const authorizationRouter = (
ctx
);

return res
.status(200)
.send(authorizationApi.Keys.parse({ keys: keys.map(keyToApiKey) }));
return res.status(200).send(
authorizationApi.Keys.parse({
keys: keys.map(keyToApiKey),
totalCount: keys.length,
})
);
} catch (error) {
const errorRes = makeApiProblem(
error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ export function authorizationServiceBuilder(
keySeed: authorizationApi.KeySeed;
},
{ logger, correlationId, authData }: WithLogger<AppContext<UIAuthData>>
): Promise<ProducerKeychain> {
): Promise<Key> {
logger.info(`Creating keys for producer keychain ${producerKeychainId}`);
const producerKeychain = await retrieveProducerKeychain(
producerKeychainId,
Expand Down Expand Up @@ -1095,7 +1095,7 @@ export function authorizationServiceBuilder(
)
);

return updatedProducerKeychain;
return newKey;
},
async removeProducerKeychainKeyById(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,22 @@ describe("createProducerKeychainKey", () => {

await addOneProducerKeychain(mockProducerKeychain);

const producerKeychain =
await authorizationService.createProducerKeychainKey(
{
producerKeychainId: mockProducerKeychain.id,
keySeed,
},
getMockContext({ authData: mockAuthData })
);
await authorizationService.createProducerKeychainKey(
{
producerKeychainId: mockProducerKeychain.id,
keySeed,
},
getMockContext({ authData: mockAuthData })
);

const writtenEvent = await readLastEventByStreamId(
producerKeychain.id,
mockProducerKeychain.id,
'"authorization"',
postgresDB
);

expect(writtenEvent).toMatchObject({
stream_id: producerKeychain.id,
stream_id: mockProducerKeychain.id,
version: "1",
type: "ProducerKeychainKeyAdded",
event_version: 2,
Expand Down
Loading