Skip to content
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

Add idempotency field #1573

Open
5 tasks done
elsand opened this issue Dec 9, 2024 · 2 comments
Open
5 tasks done

Add idempotency field #1573

elsand opened this issue Dec 9, 2024 · 2 comments
Assignees

Comments

@elsand
Copy link
Member

elsand commented Dec 9, 2024

Introduction

This introduces an independent idempotency mechanism as a field on the dialog entity

Description

See initial discussion in #1191

This will allow service providers to attempt to create dialogs supplying a custom idempotency key in the request body. This will have to be unique per org (ie serviceowner code). The field should only be visible on service owner DTOs (for create and get details). If attempting to create a dialog which collides on this field, an error should be returned. This error should also indicate the id of the existing/conflicting dialog.

Implementation

For performance reasons, we should avoid having to manually check whether the org/key already exists prior to database insertion. Instead, consider creating a composite unique key over "org" and the new field for idempotency key, and handle the constraint error instead.

Tasks

Preview Give feedback

Threat modelling

Preview Give feedback

Threats

This introduces a mechanism in which it is possible for any system to determine if a dialog exists, if the format/business rules for the utilized idempotency keys are known and predictable. This is mostly mitigated by having this unique per org. Trust boundaries will however eventually be set per system within an org (see #40), so documentation should mention this and suggest to consider using non-predictable idempotency keys (ie peppered hashes) if systems within an org does not trust each other to leak the existance of dialogs to eachother.

Acceptance criteria

GIVEN a service owner DTO with a valid idempotency key and no existing dialog with the same idempotency key for the same org
WHEN a dialog is created
THEN the dialog is successfully created, and the idempotency key is stored in the database

GIVEN a service owner DTO with a valid idempotency key that matches an existing dialog's idempotency key for the same org
WHEN a dialog creation is attempted
THEN the service returns an error indicating a conflict, including the ID of the existing dialog

GIVEN a service owner DTO with an invalid idempotency key (e.g., exceeding maximum length or malformed)
WHEN a dialog creation is attempted
THEN the service returns a validation error indicating the issue

@Fargekritt Fargekritt self-assigned this Dec 16, 2024
@Fargekritt Fargekritt mentioned this issue Dec 27, 2024
4 tasks
@elsand elsand moved this to Code Review og PR in Dialogporten / Arbeidsflate Jan 9, 2025
@Fargekritt Fargekritt moved this from Code Review og PR to Testing in Dialogporten / Arbeidsflate Feb 10, 2025
@Fargekritt Fargekritt moved this from Testing to Code Review og PR in Dialogporten / Arbeidsflate Feb 10, 2025
Fargekritt added a commit that referenced this issue Feb 10, 2025
## Description

Added IdempotentId based on self-defined id and org name

## Related Issue(s)

#1573 

## Verification

- [x] **Your** code builds clean without any errors or warnings
- [x] Manual testing done (required)
- [x] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)

---------

Co-authored-by: Magnus Sandgren <[email protected]>
Co-authored-by: Ole Jørgen Skogstad <[email protected]>
@Fargekritt Fargekritt moved this from Code Review og PR to Testing in Dialogporten / Arbeidsflate Feb 10, 2025
@LeifHelstad
Copy link

LeifHelstad commented Feb 10, 2025

Test

Første kriterie : Det finnes ingen tidligere dialog med nøkkelen

Input
"idempotentkey":"SB_1739189226540",

🟢 det dannes dialog med de nye feltet angitt i POST
"0194efc2-10c7-7712-9c5f-526100df9236"

🔴 feltet returneres ikke med GET
Image

Er den case sensitiv på stor K?
-> Nei opplever det samme med stor K i Key.

Første kriterie : Samme nøkkel kan ikke benyttes flere ganger

🔴 Kan trykke Send om og om igjen i postman med samme nøkkel.

Her er det noe feil:

  • Er koden deployet til miljøet?
  • Er feltnavnent noe annet enn "idempotentkey"?

Denne er ikke klar fort test og må vente

  • Denne endringen er i versjon 1.50.0
  • Nyeste versjon i Staging er 1.49.0

Dokumentasjonen bør oppdateres

Usikkerheten på om "idempotentkey" er rett feltnavn kommer mye av at feltet ikke er nevnt i dokumentasjonen https://docs.altinn.studio/dialogporten/reference/entities/dialog/

@LeifHelstad
Copy link

LeifHelstad commented Feb 11, 2025

Test

Nå på releaset versjon 1.50.1

Kriterie 1

Oppretter dialog 0194f42d-5e68-7756-98e6-65667144f1de
med "idempotentkey":"SB_1739263381464",

Gjør get single dilaog
🟢 Bærer tilbake samme idempotentkey, som forventet
"id": "0194f42d-5e68-7756-98e6-65667144f1de",
"idempotentKey": "SB_1739263381464",

Kriterie 2

Gjør en ny post create dialog der samme .json gjenbrukes
🟢 Avvises som forventet

Image

Kriterie 3

Angir alt for lag idempotentkey
🟢 Stoppes med feilmeldig, som forventet

Image

Grenseverdi test

🟢 37 tegn
1234567891234567891234567891234567891
"errors": {
"dto.idempotentKey": [
"The length of 'IdempotentKey' must be 36 characters or fewer. You entered 37 characters."
]
},

🟢 36 tegn
123456789123456789123456789123456789
Dialog opprettes:
"0194f44a-a783-771a-ae6a-5570225cd27e"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Testing
Development

No branches or pull requests

3 participants