Skip to content

Commit

Permalink
Added proxy for SBL Bridge for setting expired service (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechArch authored Sep 12, 2024
1 parent f4ef200 commit 40bb9fd
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Altinn.ResourceRegistry.Core/Services/IAltinn2Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ public interface IAltinn2Services
/// Request delegations
/// </summary>
Task ExportDelegations(ExportDelegationsRequestBE exportDelegationsRequestBE, CancellationToken cancellationToken = default);

/// <summary>
/// Set service edition as expired
/// </summary>
/// <returns></returns>
Task SetServiceEditionExpired(string externalServiceCode, int externalServiceEditionCode, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading;
using System.Xml;
using Altinn.Authorization.ABAC.Utils;
using Altinn.Authorization.ABAC.Xacml;
Expand Down Expand Up @@ -122,5 +123,14 @@ public async Task ExportDelegations(ExportDelegationsRequestBE exportDelegations

return policy;
}

/// <inheritdoc/>
public async Task SetServiceEditionExpired(string externalServiceCode, int externalServiceEditionCode, CancellationToken cancellationToken = default)
{
string bridgeBaseUrl = _settings.BridgeApiEndpoint;
string url = $"{bridgeBaseUrl}metadata/api/setserviceeditionexpired?externalServiceCode={externalServiceCode}&externalServiceEditionCode={externalServiceEditionCode}";
HttpResponseMessage response = await _client.GetAsync(url, cancellationToken);
response.EnsureSuccessStatusCode();
}
}
}
12 changes: 12 additions & 0 deletions src/Altinn.ResourceRegistry/Controllers/Altinn2ExportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ public async Task<ActionResult> ExportDelegations([FromBody] ExportDelegationsRe
return Created();
}

/// <summary>
/// Sets a given service expired to hide delegation functionality. Proxy for bridge functionality. Called by Altinn Studio and used as part of the migration of delegation process
/// </summary>
/// <returns></returns>
[Authorize(Policy = AuthzConstants.POLICY_ADMIN)]
[HttpGet("setserviceeditionexpired")]
public async Task<ActionResult> SetServiceEditionExpired([FromQueryAttribute] string externalServiceCode, [FromQueryAttribute] int externalServiceEditionCode, CancellationToken cancellationToken = default)
{
await _altinn2ServicesClient.SetServiceEditionExpired(externalServiceCode, externalServiceEditionCode, cancellationToken);
return Ok();
}

[NonAction]
private async Task<bool> ValidateMatchingOrgForDelegaton(ExportDelegationsRequestBE exportRequest, string org, CancellationToken cancellationToken = default)
{
Expand Down
39 changes: 39 additions & 0 deletions test/Altinn.ResourceRegistry.Tests/Altinn2ExportControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,45 @@ public async Task DelegationCount_WithoutToken()
Assert.Equal(System.Net.HttpStatusCode.Unauthorized, response.StatusCode);
}

/// <summary>
/// Calls SetExpired endpoint without token
/// </summary>
[Fact]
public async Task Setserviceeditionexpired_WithoutToken()
{
HttpClient client = CreateClient();
string requestUri = "resourceregistry/api/v1/altinn2export/setserviceeditionexpired?externalServiceCode=4485&externalServiceEditionCode=2021";

HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri)
{
};

HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

Assert.Equal(System.Net.HttpStatusCode.Unauthorized, response.StatusCode);
}

/// <summary>
/// Calls SetExpired endpoint without token
/// </summary>
[Fact]
public async Task Setserviceeditionexpired_WithValidToken()
{
HttpClient client = CreateClient();
string token = PrincipalUtil.GetOrgToken("digdir", "991825827", "altinn:resourceregistry/resource.admin");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
string requestUri = "resourceregistry/api/v1/altinn2export/setserviceeditionexpired?externalServiceCode=4485&externalServiceEditionCode=2021";

HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri)
{
};

HttpResponseMessage response = await client.SendAsync(httpRequestMessage);

Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
}


/// <summary>
/// Tries to trigger batch without Altinn Studio token
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,10 @@ public Task ExportDelegations(ExportDelegationsRequestBE exportDelegationsReques
{
return Task.CompletedTask;
}

public Task SetServiceEditionExpired(string externalServiceCode, int externalServiceEditionCode, CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
}
}

0 comments on commit 40bb9fd

Please sign in to comment.