Skip to content

VNext release #11

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

Merged
merged 21 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build & Test

on:
push:
branches: [ master ]
branches: [ master, vNext ]
pull_request:
branches: [ master ]
branches: [ master, vNext ]

jobs:
build:
Expand All @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Extract version from tag
id: get_version
uses: battila7/get-version-action@v2
Expand Down
2 changes: 2 additions & 0 deletions Kentico.Kontent.AspNetCore.Tests/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# For webhook body mock files
*.json text eol=crlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"data": {
"items": [
{
"id": "ad7be0cd-ade8-4444-bb06-9dde23ad3fc8",
"codename": "post_150",
"language": "default",
"type": "post",
"collection": "default"
}
],
"taxonomies": []
},
"message": {
"id": "3078e666-b725-44d3-b760-d81c23d56cd1",
"project_id": "74304de2-c3d4-01b7-aad3-487e219eca5b",
"type": "content_item_variant",
"operation": "publish",
"api_name": "delivery_production",
"created_timestamp": "2022-04-27T14:52:11.6851466Z",
"webhook_url": "https://webhook.site/df47e21c-14b8-4ff5-ac3a-fb7d8f3d11d4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"data": {
"items": [
{
"item": {
"id": "ad7be0cd-ade8-4444-bb06-9dde23ad3fc8"
},
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"transition_from": {
"id": "eee6db3b-545a-4785-8e86-e3772c8756f9"
},
"transition_to": {
"id": "c199950d-99f0-4983-b711-6c4c91624b22"
}
}
]
},
"message": {
"id": "352c48a1-cb76-4d1e-84a3-2f7056573be8",
"project_id": "74304de2-c3d4-01b7-aad3-487e219eca5b",
"type": "content_item_variant",
"operation": "change_workflow_step",
"api_name": "content_management",
"created_timestamp": "2022-04-27T15:52:02.4223349Z",
"webhook_url": "https://webhook.site/df47e21c-14b8-4ff5-ac3a-fb7d8f3d11d4"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -11,6 +11,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand All @@ -27,4 +28,10 @@
<ProjectReference Include="..\Kentico.Kontent.AspNetCore\Kentico.Kontent.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Data\**\*.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
46 changes: 45 additions & 1 deletion Kentico.Kontent.AspNetCore.Tests/SignatureMiddlewareTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using Kentico.Kontent.AspNetCore.Webhooks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -25,7 +31,7 @@ public async Task RequestWithoutSignature_ReturnsUnauthorized()
}

[Fact]
public async Task RequestWithInvalidSignature_ReturnsUnauthorized()
public async Task RequestWithInvalidSignatureEmptyBody_ReturnsUnauthorized()
{
// Arrange
var options = Options.Create(new WebhookOptions { });
Expand All @@ -39,5 +45,43 @@ public async Task RequestWithInvalidSignature_ReturnsUnauthorized()
// Assert
Assert.Equal(ctx.Response.StatusCode, (int)HttpStatusCode.Unauthorized);
}

[Theory]
[InlineData("ezKcSmuYrugdCN73QVWDXREaNY7AkUhFWksUFlp9Tnc=", "PublishDeliveryTriggerWebhookBody.json", "fiJ+MiJxiqmzbnlVzWnR+7Rgas7aDSzsqIApflYiZ4o=", HttpStatusCode.NotFound)]
[InlineData("8UXIHkZ6KuarukFbZDhzyeVAHcKkFnlLabScv9VyNww=", "PublishManagementTriggerWebhookBody.json", "khBZy02UmiUrp2bl1ooPJdILKUmmL2Q7kx318+arMhM=", HttpStatusCode.NotFound)]
[InlineData("8UXIHkZ6KuarukFbZDhzyeVAHcKkFnlLabScv9VyNww=", "PublishDeliveryTriggerWebhookBody.json", "tampered-body-hash", HttpStatusCode.Unauthorized)]
[InlineData("8UXIHkZ6KuarukFbZDhzyeVAHcKkFnlLabScv9VyNww=", "PublishManagementTriggerWebhookBody.json", "tampered-body-hash", HttpStatusCode.Unauthorized)]
// https://docs.microsoft.com/en-us/aspnet/core/test/middleware
public async Task TriggerRequest_WithValidSignature_CorrectStatusSet(string authorizationSecret, string bodyFilename, string signature, HttpStatusCode resultStatus)
{
using var host = await new HostBuilder()
.ConfigureWebHost(webBuilder =>
{
webBuilder
.UseTestServer()
.Configure(app =>
{
app.UseWebhookSignatureValidator(context =>
true,
new WebhookOptions
{
Secret = authorizationSecret
}
);
});
})
.StartAsync();

var responsePath = Path.Combine(Environment.CurrentDirectory, "Data", bodyFilename);
var server = host.GetTestServer();
var context = await server.SendAsync(c =>
{
c.Request.Method = HttpMethods.Post;
c.Request.Headers.Add("X-KC-Signature", signature);
c.Request.Body = new StringContent(File.ReadAllText(responsePath)).ReadAsStream();
});

Assert.Equal(context.Response.StatusCode, (int)resultStatus);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Kentico.Kontent.Delivery.Abstractions;
using Kentico.Kontent.ImageTransformation;
using Kentico.Kontent.Urls.ImageTransformation;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Authors>Kentico Software</Authors>
<Product>Kentico Kontent</Product>
Expand All @@ -22,9 +22,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Kentico.Kontent.Delivery.Abstractions" Version="14.2.1" />
<PackageReference Include="Kentico.Kontent.ImageTransformation" Version="14.2.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Kentico.Kontent.Urls" Version="16.0.0" />
<PackageReference Include="Kentico.Kontent.Delivery.Abstractions" Version="16.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Kentico.Kontent.AspNetCore.Webhooks.Models
{
/// <summary>
/// Root object of a Kentico Kontent webhook.
/// </summary>
public class WebhookModel
{
/// <summary>
/// The Message object contains information about the origin of the notification.
/// </summary>
[JsonPropertyName("message")]
public Message Message { get; set; }

/// <summary>
/// Data relevant to the operation that triggered the webhook.
/// </summary>
[JsonPropertyName("data")]
public Data Data { get; set; }
}

/// <summary>
/// The Message object contains information about the origin of the notification.
/// </summary>
Expand All @@ -32,6 +18,12 @@ public class Message
[JsonPropertyName("id")]
public Guid Id { get; set; }

/// <summary>
/// Identifier of a Kontent project.
/// </summary>
[JsonPropertyName("project_id")]
public Guid? ProjectId { get; set; }

/// <summary>
/// Type of the object that triggered the webhook (content_item_variant, taxonomy, ...)
/// </summary>
Expand All @@ -50,12 +42,6 @@ public class Message
[JsonPropertyName("api_name")]
public string ApiName { get; set; }

/// <summary>
/// Identifier of a Kentico Kontent project.
/// </summary>
[JsonPropertyName("project_id")]
public Guid ProjectId { get; set; }

/// <summary>
/// Timestamp of the webhook.
/// </summary>
Expand All @@ -69,53 +55,6 @@ public class Message
public string WebhookUrl { get; set; }
}

/// <summary>
/// Data relevant to the operation that triggered the webhook.
/// </summary>
public class Data
{
/// <summary>
/// A collection of Item objects for each modified content item.
/// </summary>
[JsonPropertyName("items")]
public Item[] Items { get; set; }

/// <summary>
/// A collection of Taxonomy group objects.
/// </summary>
[JsonPropertyName("taxonomies")]
public Taxonomy[] Taxonomies { get; set; }
}

/// <summary>
/// A Content item object.
/// </summary>
public class Item
{
/// <summary>
/// The content item's internal ID.
/// </summary>
public string Id { get; set; }

/// <summary>
/// The language's codename.
/// </summary>
[JsonPropertyName("language")]
public string Language { get; set; }

/// <summary>
/// The content type's codename.
/// </summary>
[JsonPropertyName("type")]
public string Type { get; set; }

/// <summary>
/// The content item's codename.
/// </summary>
[JsonPropertyName("codename")]
public string Codename { get; set; }
}

/// <summary>
/// A Taxonomy group object.
/// </summary>
Expand All @@ -124,6 +63,7 @@ public class Taxonomy
/// <summary>
/// The taxonomy group's internal ID.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
Expand Down
Loading