diff --git a/BrowserCache/SessionStorageCacheTests.cs b/BrowserCache/SessionStorageCacheTests.cs index 0aebb0b..c0ee3d9 100644 --- a/BrowserCache/SessionStorageCacheTests.cs +++ b/BrowserCache/SessionStorageCacheTests.cs @@ -168,7 +168,7 @@ private void RunTest(WebDriver driver, bool enableCookies) ClientServerUrl, _app.BaseUrl.ToString(), BuildPage(enableCookies), - ExampleApps.JsonEndpointPath, + ExampleApps.JsonEndpointPaths, clientServerTokenSource.Token); clientServer = serverListener.Listener; clientHttpServer = serverListener.Server; @@ -265,9 +265,12 @@ private static void AssertSameResults( private int CountJsonPosts() { - var expected = $"POST {ExampleApps.JsonEndpointPath}"; + var expected = ExampleApps.JsonEndpointPaths + .Select(p => $"POST {p}") + .ToList(); return clientHttpServer.RequestLog - .Count(r => string.Equals(r, expected, StringComparison.OrdinalIgnoreCase)); + .Count(r => expected.Any(e => string.Equals( + r, e, StringComparison.OrdinalIgnoreCase))); } private static List GetSessionStorageKeys(IJavaScriptExecutor js) diff --git a/Examples/ExampleApps.cs b/Examples/ExampleApps.cs index 4f6414c..e234629 100644 --- a/Examples/ExampleApps.cs +++ b/Examples/ExampleApps.cs @@ -32,6 +32,25 @@ public static class ExampleApps ? descriptor.JsonEndpointPath : "/51dpipeline/json"; + /// + /// Every path the selected language's client-side script may post to, + /// being and any older path the + /// language still answers. + /// + public static IReadOnlyList JsonEndpointPaths + { + get + { + var paths = new List { JsonEndpointPath }; + if (Descriptors.TryGetValue(SelectedLang, out var descriptor) + && descriptor.AlternativeJsonEndpointPaths != null) + { + paths.AddRange(descriptor.AlternativeJsonEndpointPaths); + } + return paths; + } + } + /// /// Element the selected language's page renders its client-side results /// into. Read from the descriptor so it is available for the CI case @@ -219,8 +238,13 @@ public static ExampleAppOptions BuildOptions( StartupTimeoutSeconds: 180, BuildEnv: o => new Dictionary { + // The example reads the _51DEGREES_ names. Released + // versions of it read the two older names, so both + // are set until every language has released. + ["_51DEGREES_RESOURCE_KEY"] = o.ResourceKey, ["SUPER_RESOURCE_KEY"] = o.ResourceKey, // the endpoint must include the api/v4 path + ["_51DEGREES_CLOUD_ENDPOINT"] = new Uri(o.CloudEndpoint, "api/v4/").ToString(), ["FIFTYONE_CLOUD_ENDPOINT"] = new Uri(o.CloudEndpoint, "api/v4/").ToString(), ["ASPNETCORE_URLS"] = $"http://localhost:{o.Port}", // run on a newer .NET runtime if the exact one isn't installed @@ -245,7 +269,7 @@ public static ExampleAppOptions BuildOptions( BuildArgs: new[] { "-pl", "web/getting-started.cloud", "-am", "package", "-DskipTests" }, RunArtifactGlob: "web/getting-started.cloud/target/*-jar-with-dependencies.jar", BuildTimeoutSeconds: 600, - JsonEndpointPath: "/51Degrees.core.json", + AlternativeJsonEndpointPaths: new[] { "/51Degrees.core.json" }, // the java page renders the client-side results into its // Apple detection section rather than the shared container ClientResultsElementId: "apple-detection"), diff --git a/Examples/ExampleAppsTests.cs b/Examples/ExampleAppsTests.cs index 3f271e6..0e5ce16 100644 --- a/Examples/ExampleAppsTests.cs +++ b/Examples/ExampleAppsTests.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -74,5 +76,23 @@ public void Descriptors_Rust_BuildsAndRunsWithCargo() Assert.IsTrue(rust.Args.Contains("dd-web-getting-started-cloud"), "run args should target the cloud getting-started web binary"); } + + [TestMethod] + public void Descriptors_Dotnet_SetsTheUnderscoreNames() + { + var dotnet = ExampleApps.Descriptors["dotnet"]; + var env = dotnet.BuildEnv(new ExampleAppOptions( + Port: 5123, + CloudEndpoint: new Uri("https://cloud.example.test/"), + ResourceKey: "key", + ExtraEnv: new Dictionary())); + Assert.AreEqual("key", env["_51DEGREES_RESOURCE_KEY"], + "the example reads the resource key from this name"); + Assert.AreEqual( + "https://cloud.example.test/api/v4/", + env["_51DEGREES_CLOUD_ENDPOINT"], + "the example reads the endpoint, with its api/v4 path, " + + "from this name"); + } } } diff --git a/Examples/ExampleDescriptor.cs b/Examples/ExampleDescriptor.cs index f876a1d..f2909c2 100644 --- a/Examples/ExampleDescriptor.cs +++ b/Examples/ExampleDescriptor.cs @@ -23,7 +23,12 @@ namespace FiftyOne.Pipeline.Cloud.SeleniumTests.Examples /// integration picks its own, so a test that proxies or counts those /// requests has to ask the descriptor rather than assume one: dotnet and /// rust use the default, java uses /51Degrees.core.json, and node, python - /// and php use /json. + /// and php use /json, and java uses the default and still answers the + /// older /51Degrees.core.json. + /// + /// + /// Older paths the integration still answers, so a test accepts a build + /// whose script uses either. /// /// /// Id of the element the example's page asks the shared examples helper to @@ -44,5 +49,6 @@ public sealed record ExampleDescriptor( string RunArtifactGlob = null, int BuildTimeoutSeconds = 0, string JsonEndpointPath = "/51dpipeline/json", - string ClientResultsElementId = "content"); + string ClientResultsElementId = "content", + IReadOnlyList AlternativeJsonEndpointPaths = null); } diff --git a/TestsCommon/Helpers/TestHelpers.cs b/TestsCommon/Helpers/TestHelpers.cs index a4ab1b7..70ee654 100644 --- a/TestsCommon/Helpers/TestHelpers.cs +++ b/TestsCommon/Helpers/TestHelpers.cs @@ -103,28 +103,32 @@ public static ServerListener ReverseProxyListener( /// Creates an HttpListener that serves /// for page paths and proxies the 51Degrees script and pipeline /// endpoints to without caching. - /// is the path the client-side - /// script posts refreshed evidence to, which differs per web - /// integration, so the caller supplies the one its example uses. + /// are the paths the client-side + /// script may post refreshed evidence to, which differ per web + /// integration, so the caller supplies the ones its example uses. /// public static ServerListener ExampleProxyListener( string clientUrl, string exampleUrl, string pageData, - string jsonEndpointPath, + IEnumerable jsonEndpointPaths, CancellationToken token) { var listener = new HttpListener(); listener.Prefixes.Add(clientUrl); listener.Start(); + var routes = new Dictionary + { + ["/51Degrees.core.js"] = exampleUrl, + }; + foreach (var path in jsonEndpointPaths) + { + routes[path] = exampleUrl; + } var server = new HttpServer(listener, pageData) { - ProxyRoutes = new Dictionary - { - ["/51Degrees.core.js"] = exampleUrl, - [jsonEndpointPath] = exampleUrl, - }, + ProxyRoutes = routes, ProxiedHeaderOverrides = new Dictionary { ["Cache-Control"] = "no-store",