-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use different wiremock instances to differentiate Vonage re…
…quests and OIDC requests
- Loading branch information
Showing
4 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
using Vonage.Serialization; | ||
using Vonage.Test.Common; | ||
using Vonage.Test.TestHelpers; | ||
|
||
namespace Vonage.Test.NumberVerification; | ||
|
||
public class E2EBase | ||
{ | ||
internal readonly TestingContext Helper; | ||
internal readonly OidcTestingContext Helper; | ||
internal readonly SerializationTestHelper Serialization; | ||
|
||
protected E2EBase(string serializationNamespace) : this() => this.Serialization = | ||
new SerializationTestHelper(serializationNamespace, JsonSerializerBuilder.BuildWithSnakeCase()); | ||
|
||
protected E2EBase() => this.Helper = TestingContext.WithBearerCredentials(); | ||
protected E2EBase() => this.Helper = OidcTestingContext.WithBearerCredentials(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Configuration; | ||
using Vonage.Request; | ||
using Vonage.Test.Common.TestHelpers; | ||
using WireMock.Server; | ||
using TimeProvider = Vonage.Common.TimeProvider; | ||
|
||
namespace Vonage.Test.NumberVerification; | ||
|
||
internal class OidcTestingContext : IDisposable | ||
{ | ||
private OidcTestingContext(Credentials credentials, string authorizationHeaderValue, | ||
Dictionary<string, string> settings) | ||
{ | ||
this.ExpectedAuthorizationHeaderValue = authorizationHeaderValue; | ||
this.VonageServer = WireMockServer.Start(); | ||
this.OidcServer = WireMockServer.Start(); | ||
settings.Add(VonageUrls.NexmoApiKey, this.VonageServer.Url); | ||
settings.Add($"{VonageUrls.NexmoApiKey}.EMEA", this.VonageServer.Url); | ||
settings.Add($"{VonageUrls.NexmoApiKey}.APAC", this.VonageServer.Url); | ||
settings.Add($"{VonageUrls.NexmoApiKey}.AMER", this.VonageServer.Url); | ||
settings.Add(VonageUrls.NexmoRestKey, this.VonageServer.Url); | ||
settings.Add(VonageUrls.VideoApiKey, this.VonageServer.Url); | ||
settings.Add(VonageUrls.OidcApiKey, this.OidcServer.Url); | ||
var configuration = | ||
Configuration.FromConfiguration(new ConfigurationBuilder().AddInMemoryCollection(settings).Build()); | ||
this.VonageClient = new VonageClient(credentials, configuration, new TimeProvider()); | ||
} | ||
|
||
public string ExpectedAuthorizationHeaderValue { get; protected init; } | ||
public WireMockServer VonageServer { get; } | ||
public WireMockServer OidcServer { get; } | ||
public VonageClient VonageClient { get; } | ||
|
||
public void Dispose() | ||
{ | ||
this.Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
public static OidcTestingContext WithBearerCredentials() => | ||
new OidcTestingContext(CreateBearerCredentials(), "Bearer *", new Dictionary<string, string>()); | ||
|
||
private static Credentials CreateBearerCredentials() => Credentials.FromAppIdAndPrivateKey( | ||
Guid.NewGuid().ToString(), | ||
TokenHelper.GetKey()); | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposing) | ||
{ | ||
return; | ||
} | ||
|
||
this.VonageServer.Stop(); | ||
this.VonageServer.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters