Skip to content

Commit 1ddc2ff

Browse files
Adds support for blocking unmocked requests. Closes #311 (#325)
1 parent cbbb256 commit 1ddc2ff

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

m365-developer-proxy-plugins/MockResponses/MockResponsePlugin.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Microsoft365.DeveloperProxy.Plugins.MockResponses;
1818
public class MockResponseConfiguration {
1919
public bool NoMocks { get; set; } = false;
2020
public string MocksFile { get; set; } = "responses.json";
21+
public bool BlockUnmockedRequests { get; set; } = false;
2122

2223
[JsonPropertyName("responses")]
2324
public IEnumerable<MockResponse> Responses { get; set; } = Array.Empty<MockResponse>();
@@ -98,6 +99,18 @@ protected virtual async Task OnRequest(object? sender, ProxyRequestArgs e) {
9899
ProcessMockResponse(e.Session, matchingResponse);
99100
state.HasBeenSet = true;
100101
}
102+
else if (_configuration.BlockUnmockedRequests) {
103+
ProcessMockResponse(e.Session, new MockResponse {
104+
Method = request.Method,
105+
Url = request.Url,
106+
ResponseCode = 502,
107+
ResponseBody = new GraphErrorResponseBody(new GraphErrorResponseError {
108+
Code = "Bad Gateway",
109+
Message = $"No mock response found for {request.Method} {request.Url}"
110+
})
111+
});
112+
state.HasBeenSet = true;
113+
}
101114
}
102115
}
103116

0 commit comments

Comments
 (0)