Skip to content

[BUG]: MockGeneratorPlugin errors if the response has a duplicate header #358

@mosoftwareenterprises

Description

@mosoftwareenterprises

Description

When recording to generate mocks automatically. If a response has the same keyed header more than once, then a Dictionary error is seen.

This seems to happen most with google related requests.

Expected behaviour

No exception thrown when the mocks are generated.

Actual behaviour

An exception is thrown about duplicate keys:

Processing request GET https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=https://login.microsoftonline.com/98eb52c1-3151-4f00-a3be-d05cf4686ec4/oauth2/authorize...
Unhandled Exception Handler caught : System.ArgumentException: An item with the same key has already been added. Key: Set-Cookie
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Microsoft365.DeveloperProxy.Plugins.RequestLogs.MockGeneratorPlugin.AfterRecordingStop(Object sender, RecordingArgs e) in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy-plugins\RequestLogs\MockGeneratorPlugin.cs:line 53
   at Microsoft365.DeveloperProxy.Abstractions.PluginEvents.RaiseRecordingStopped(RecordingArgs args) in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy-abstractions\PluginEvents.cs:line 304
   at Microsoft365.DeveloperProxy.ProxyEngine.StopRecording() in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy\ProxyEngine.cs:line 228
   at Microsoft365.DeveloperProxy.ProxyEngine.Console_CancelKeyPress(Object sender, ConsoleCancelEventArgs e) in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy\ProxyEngine.cs:line 284
   at System.Console.HandlePosixSignal(PosixSignalContext ctx)
   at System.Runtime.InteropServices.PosixSignalRegistration.HandlerRoutine(Int32 dwCtrlType)
Proxy stoppped
Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: Set-Cookie
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Microsoft365.DeveloperProxy.Plugins.RequestLogs.MockGeneratorPlugin.AfterRecordingStop(Object sender, RecordingArgs e) in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy-plugins\RequestLogs\MockGeneratorPlugin.cs:line 53
   at Microsoft365.DeveloperProxy.Abstractions.PluginEvents.RaiseRecordingStopped(RecordingArgs args) in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy-abstractions\PluginEvents.cs:line 304
   at Microsoft365.DeveloperProxy.ProxyEngine.StopRecording() in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy\ProxyEngine.cs:line 228
   at Microsoft365.DeveloperProxy.ProxyEngine.Console_CancelKeyPress(Object sender, ConsoleCancelEventArgs e) in D:\OakInnovations\m365-developer-proxy\m365-developer-proxy\ProxyEngine.cs:line 284
   at System.Console.HandlePosixSignal(PosixSignalContext ctx)
   at System.Runtime.InteropServices.PosixSignalRegistration.HandlerRoutine(Int32 dwCtrlType)

Steps to reproduce

I created it by running the command:

./m365proxy --record --summary-file-path report.md --summary-group-by messageType

And my urlsToWatch set to

  "urlsToWatch": [
    "https://*/*"
  ],

Microsoft 365 Developer Proxy Version

0.12.0

Operating system (environment)

Windows

Shell

PowerShell

Additional Info

No response

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions