Altinn / Altinn/app-lib-dotnet

Validate that called action is configured for task in bpmn

Open
#1,133 0 comments 0 reactions 0 assignees View on GitHub
kind/chore status/draft status/triage
Dominant language
C#
Stars
8
Forks
27
Avg merge
1h 21m
Merged PRs (30d)
7

Description

### Description

We don't currently validate that the called action is actually configured for the task in BPMN. As long as authorization returns 'true', the action is allowed.

We should probably require the action to be configured in BPMN.

### Additional Information

Something like:
```
if (processNext?.Action != null && _processReader.IsActionAllowedForTask(currentTaskId, processNext?.Action)
{
return Conflict(
new ProblemDetails()
{
Status = StatusCodes.Status409Conflict,
Title = $"The action '{processNext?.Action}' is not allowed for task '{currentTaskId}'!",
}
);
}
```

```
[Fact]
public async Task RunNextWithAction_WhenActionIsNotDefinedInBpmn_ReturnsConflict()
{
var pdfMock = new Mock(MockBehavior.Strict);
using var pdfReturnStream = new MemoryStream();
pdfMock.Setup(p => p.GeneratePdf(It.IsAny(), It.IsAny())).ReturnsAsync(pdfReturnStream);
OverrideServicesForThisTest = (services) =>
{
services.AddSingleton(pdfMock.Object);
};
using var client = GetRootedUserClient(Org, App, 1337, InstanceOwnerPartyId);
using var content = new StringContent(
"""{"action": "unknown-action_not_in_bpmn_task"}""",
Encoding.UTF8,
"application/json"
);
var nextResponse = await client.PutAsync($"{Org}/{App}/instances/{_instanceId}/process/next", content);
var nextResponseContent = await nextResponse.Content.ReadAsStringAsync();
OutputHelper.WriteLine(nextResponseContent);
nextResponse.Should().HaveStatusCode(HttpStatusCode.Conflict);
}
```

### Tasks

_No response_

### Acceptance Criterias

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the process-next endpoint and inspect how the requested action is authorized against the current BPMN task, including _processReader.IsActionAllowedForTask. Add the RunNextWithAction_WhenActionIsNotDefinedInBpmn_ReturnsConflict test shown in the issue and verify that an action missing from the BPMN task produces HTTP 409 Conflict.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.