Skip to content

Commit

Permalink
altinn:/notifications.create -> serviceowner scope
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad committed Oct 27, 2023
1 parent 69b3bd8 commit 215bb17
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Altinn.Notifications.Core.Repository.Interfaces;
using Altinn.Notifications.Persistence.Configuration;
using Altinn.Notifications.Persistence.Health;
using Altinn.Notifications.Persistence.Repository;

using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -45,11 +44,7 @@ public static void AddPostgresHealthChecks(this IServiceCollection services, ICo
.Get<PostgreSqlSettings>()
?? throw new ArgumentNullException(nameof(config), "Required PostgreSQLSettings is missing from application configuration");

string connectionString = string.Format(settings.ConnectionString, settings.NotificationsDbPwd);

var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);

services.AddHealthChecks()
.AddCheck("notifications_postgres_health_check", new PostgresHealthCheck(dataSourceBuilder.Build()));
.AddNpgSql(string.Format(string.Format(settings.ConnectionString, settings.NotificationsDbPwd)), name: "notifications_postgres_health_check");

Check failure on line 48 in src/Altinn.Notifications.Persistence/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'IHealthChecksBuilder' does not contain a definition for 'AddNpgSql' and no accessible extension method 'AddNpgSql' accepting a first argument of type 'IHealthChecksBuilder' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in src/Altinn.Notifications.Persistence/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'IHealthChecksBuilder' does not contain a definition for 'AddNpgSql' and no accessible extension method 'AddNpgSql' accepting a first argument of type 'IHealthChecksBuilder' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in src/Altinn.Notifications.Persistence/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

'IHealthChecksBuilder' does not contain a definition for 'AddNpgSql' and no accessible extension method 'AddNpgSql' accepting a first argument of type 'IHealthChecksBuilder' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in src/Altinn.Notifications.Persistence/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

'IHealthChecksBuilder' does not contain a definition for 'AddNpgSql' and no accessible extension method 'AddNpgSql' accepting a first argument of type 'IHealthChecksBuilder' could be found (are you missing a using directive or an assembly reference?)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public static class AuthorizationConstants
/// <summary>
/// Scope for allowing access to creating notifications
/// </summary>
public const string SCOPE_NOTIFICATIONS_CREATE = "altinn:notifications.create";
public const string SCOPE_NOTIFICATIONS_CREATE = "altinn:serviceowner/notifications.create";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task Post_InvalidScopeInToken_Forbidden()
public async Task Post_EmptyBody_BadRequest()
{
HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath)
{
Expand All @@ -132,7 +132,7 @@ public async Task Post_ValidationReturnsError_BadRequest()
.Returns(new ValidationResult(new List<ValidationFailure> { new ValidationFailure("SomeProperty", "SomeError") }));

HttpClient client = GetTestClient(validator.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ public async Task Post_ServiceReturnsError_ServerError()
.ReturnsAsync((null, new ServiceError(500)));

HttpClient client = GetTestClient(orderService: serviceMock.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath)
{
Expand Down Expand Up @@ -210,7 +210,7 @@ public async Task Post_ValidScope_ServiceReturnsOrder_Accepted()
.ReturnsAsync((_order, null));

HttpClient client = GetTestClient(orderService: serviceMock.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath)
{
Expand All @@ -223,7 +223,7 @@ public async Task Post_ValidScope_ServiceReturnsOrder_Accepted()

// Assert
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize<OrderIdExt>(respoonseString);
OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize<OrderIdExt>(respoonseString);
Assert.NotNull(orderIdObjectExt);
Assert.Equal(_order.Id, orderIdObjectExt.OrderId);
Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString());
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task Post_ValidAccessToken_ServiceReturnsOrder_Accepted()

// Assert
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize<OrderIdExt>(respoonseString);
OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize<OrderIdExt>(respoonseString);
Assert.NotNull(orderIdObjectExt);
Assert.Equal(_order.Id, orderIdObjectExt.OrderId);
Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString());
Expand All @@ -289,7 +289,7 @@ public async Task Post_OrderWithoutFromAddress_StringEmptyUsedAsServiceInput_Acc
.ReturnsAsync((_order, null));

HttpClient client = GetTestClient(orderService: serviceMock.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

EmailNotificationOrderRequestExt request = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task Post_ServiceReturnsOrderWIthId_Accepted()
{
// Arrange
HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath)
{
Expand All @@ -90,7 +90,7 @@ public async Task Post_OrderWithoutSendersRef_Accepted()
{
// Arrange
HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task GetById_NoMatchInDb_ReturnsNotFound()
string uri = $"{_basePath}/{Guid.NewGuid()}";

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);

Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task GetById_SingleMatchInDb_ReturnsOk()
string uri = $"{_basePath}/{persistedOrder.Id}";

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task GetBySendersRef_NoMatchInDb_ReturnsOK_EmptyList()
string sendersReference = $"{_sendersRefBase}-{Guid.NewGuid()}";

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string uri = $"{_basePath}?sendersReference={sendersReference}";
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);
Expand All @@ -65,7 +65,7 @@ public async Task GetBySendersRef_SingleMatchInDb_ReturnsOk_SingleElementInlList
NotificationOrder persistedOrder = await PostgreUtil.PopulateDBWithOrder(sendersReference: sendersReference);

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string uri = $"{_basePath}?sendersReference={sendersReference}";
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);
Expand All @@ -92,7 +92,7 @@ public async Task GetBySendersRef_MultipleMatchInDb_ReturnsOk_MultipleElementInl
await PostgreUtil.PopulateDBWithOrder(sendersReference: sendersReference);

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string uri = $"{_basePath}?sendersReference={sendersReference}";
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task GetWithStatusById_NoMatchInDb_ReturnsNotFound()
string uri = $"{_basePath}/{Guid.NewGuid()}/status";

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);

Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task GetWithStatusById_SingleMatchInDbAndOneEmail_ReturnsOk()
string uri = $"{_basePath}/{persistedOrder.Id}/status";

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);

Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task GetWithStatusById_SingleMatchInDb_ReturnsOk()
string uri = $"{_basePath}/{persistedOrder.Id}/status";

HttpClient client = GetTestClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, uri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task GetBySendersRef_ValidBearerToken_CorrespondingServiceMethodCal
.ReturnsAsync((new List<NotificationOrder>() { _order }, null));

HttpClient client = GetTestClient(orderService.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string url = _basePath + "?sendersReference=" + "internal-ref";
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, url);
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task GetById_ValidBearerToken_CorrespondingServiceMethodCalled()
.ReturnsAsync((_order, null));

HttpClient client = GetTestClient(orderService.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string url = _basePath + "/" + orderId;
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, url);
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task GetById_ServiceReturnsError_StatusCodeMatchesError()
.ReturnsAsync((null, new ServiceError(404)));

HttpClient client = GetTestClient(orderService.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string url = _basePath + "/" + orderId;
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, url);
Expand Down Expand Up @@ -336,7 +336,7 @@ public async Task GetWithStatusById_ValidBearerToken_CorrespondingServiceMethodC
.ReturnsAsync((_orderWithStatus, null));

HttpClient client = GetTestClient(orderService.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string url = _basePath + "/" + orderId + "/status";
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, url);
Expand Down Expand Up @@ -387,7 +387,7 @@ public async Task GetWithStatusById_ServiceReturnsError_StatusCodeMatchesError()
.ReturnsAsync((null, new ServiceError(404)));

HttpClient client = GetTestClient(orderService.Object);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:notifications.create"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd", scope: "altinn:serviceowner/notifications.create"));

string url = _basePath + "/" + orderId + "/status";
HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, url);
Expand Down
2 changes: 1 addition & 1 deletion test/k6/src/tests/orders_email.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const orderRequestJson = JSON.parse(
);
import { generateJUnitXML, reportPath } from "../report.js";
import { addErrorCount, stopIterationOnFail } from "../errorhandler.js";
const scopes = "altinn:notifications.create";
const scopes = "altinn:serviceowner/notifications.create";
const emailRecipient = __ENV.emailRecipient.toLowerCase();

export const options = {
Expand Down

0 comments on commit 215bb17

Please sign in to comment.