Skip to content

Commit 3222899

Browse files
committed
Add test to verify that workflow with http action with managed identity for authentication fails
1 parent aa3f53a commit 3222899

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

src/LogicAppUnit.Samples.LogicApps.Tests/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public static class Constants
1515
public static readonly string FLUENT_REQUEST_MATCHING_WORKFLOW = "fluent-workflow";
1616
public static readonly string HTTP_WORKFLOW = "http-workflow";
1717
public static readonly string HTTP_ASYNC_WORKFLOW = "http-async-workflow";
18+
public static readonly string HTTP_WITH_MANAGED_IDENTITY_WORKFLOW = "http-with-managed-identity-workflow";
1819
public static readonly string INLINE_SCRIPT_WORKFLOW = "inline-script-workflow";
1920
public static readonly string INVOKE_WORKFLOW = "invoke-workflow";
2021
public static readonly string LOOP_WORKFLOW = "loop-workflow";
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using LogicAppUnit.Helper;
9+
using LogicAppUnit.Mocking;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
12+
namespace LogicAppUnit.Samples.LogicApps.Tests.HttpWithManagedIdentityWorkflow
13+
{
14+
/// <summary>
15+
/// Test cases for the <i>http-with-managed-identity-workflow</i> workflow which has an HTTP action with Managed Identity as the authentication type.
16+
/// </summary>
17+
[TestClass]
18+
public class HttpWithManagedIdentityWorkflowTest : WorkflowTestBase
19+
{
20+
[TestInitialize]
21+
public void TestInitialize()
22+
{
23+
Initialize(Constants.LOGIC_APP_TEST_EXAMPLE_BASE_PATH, Constants.HTTP_WITH_MANAGED_IDENTITY_WORKFLOW);
24+
}
25+
26+
[ClassCleanup]
27+
public static void CleanResources()
28+
{
29+
Close();
30+
}
31+
32+
/// <summary>
33+
/// Tests that the correct response is returned when the HTTP call to the Service to get the customers is successful.
34+
/// </summary>
35+
[TestMethod]
36+
public void HttpWithManagedIdentityWorkflowTest_When_Successful()
37+
{
38+
using (ITestRunner testRunner = CreateTestRunner())
39+
{
40+
// Configure mock responses
41+
testRunner
42+
.AddMockResponse(
43+
MockRequestMatcher.Create()
44+
.UsingGet()
45+
.WithPath(PathMatchType.Exact, "/api/v1/customers"))
46+
.RespondWith(
47+
MockResponseBuilder.Create()
48+
.WithSuccess());
49+
50+
// Run the workflow
51+
var workflowResponse = testRunner.TriggerWorkflow(HttpMethod.Post);
52+
53+
// Check workflow run status
54+
Assert.AreEqual(WorkflowRunStatus.Succeeded, testRunner.WorkflowRunStatus);
55+
56+
// Check workflow response
57+
testRunner.ExceptionWrapper(() => Assert.AreEqual(HttpStatusCode.OK, workflowResponse.StatusCode));
58+
59+
// Check action result
60+
Assert.AreEqual(ActionStatus.Succeeded, testRunner.GetWorkflowActionStatus("Get_Customers_from_Service_One"));
61+
Assert.AreEqual(ActionStatus.Succeeded, testRunner.GetWorkflowActionStatus("Success_Response"));
62+
}
63+
}
64+
}
65+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"definition": {
3+
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
4+
"actions": {
5+
"Get_Customers_from_Service_One": {
6+
"type": "Http",
7+
"description": "Track some properties in this action",
8+
"inputs": {
9+
"uri": "@{parameters('ServiceOne-Url')}/customers",
10+
"method": "GET",
11+
"headers": {
12+
"x-api-key": "ApiKey @{parameters('ServiceOne-Authentication-APIKey')}"
13+
},
14+
"authentication": {
15+
"type": "ManagedServiceIdentity",
16+
"audience": "api://sample-audience"
17+
}
18+
},
19+
"runAfter": {},
20+
"operationOptions": "DisableAsyncPattern"
21+
},
22+
"Success_Response": {
23+
"type": "Response",
24+
"kind": "Http",
25+
"inputs": {
26+
"statusCode": 200
27+
},
28+
"runAfter": {
29+
"Get_Customers_from_Service_One": [
30+
"SUCCEEDED"
31+
]
32+
}
33+
}
34+
},
35+
"contentVersion": "1.0.0.0",
36+
"outputs": {},
37+
"triggers": {
38+
"Receive_HTTP_request": {
39+
"type": "Request",
40+
"kind": "Http",
41+
"inputs": {
42+
"method": "POST"
43+
},
44+
"operationOptions": "SuppressWorkflowHeadersOnResponse"
45+
}
46+
}
47+
},
48+
"kind": "Stateful"
49+
}

0 commit comments

Comments
 (0)