Add endpoint to samples for automated deployment usage
This commit is contained in:
parent
76e6d0279b
commit
60d7ec5647
|
|
@ -1,4 +1,4 @@
|
|||
param($RootDirectory = (Get-Location), $Framework = "netcoreapp2.1", $Runtime = "win7-x64", $CommitHash, $BranchName, $BuildNumber)
|
||||
param($RootDirectory = (Get-Location), $Framework = "netcoreapp2.2", $Runtime = "win7-x64", $CommitHash, $BranchName, $BuildNumber)
|
||||
|
||||
# De-Powershell the path
|
||||
$RootDirectory = (Convert-Path $RootDirectory)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
|
@ -12,6 +14,8 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Http.Connections;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace FunctionalTests
|
||||
|
|
@ -103,6 +107,36 @@ namespace FunctionalTests
|
|||
await context.Response.WriteAsync(GenerateJwtToken());
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.Request.Path.StartsWithSegments("/deployment"))
|
||||
{
|
||||
var attributes = Assembly.GetAssembly(typeof(Startup)).GetCustomAttributes<AssemblyMetadataAttribute>();
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
using (var textWriter = new StreamWriter(context.Response.Body))
|
||||
using (var writer = new JsonTextWriter(textWriter))
|
||||
{
|
||||
var json = new JObject();
|
||||
var commitHash = string.Empty;
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
json.Add(attribute.Key, attribute.Value);
|
||||
|
||||
if (string.Equals(attribute.Key, "CommitHash"))
|
||||
{
|
||||
commitHash = attribute.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(commitHash))
|
||||
{
|
||||
json.Add("GitHubUrl", $"https://github.com/aspnet/SignalR/commit/{commitHash}");
|
||||
}
|
||||
|
||||
json.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
import { HttpTransportType, IHubProtocol, JsonHubProtocol } from "@aspnet/signalr";
|
||||
import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack";
|
||||
|
||||
export const ECHOENDPOINT_URL = "http://" + document.location.host + "/echo";
|
||||
export const ENDPOINT_BASE_URL = document.location.protocol + "//" + document.location.host;
|
||||
export const ECHOENDPOINT_URL = ENDPOINT_BASE_URL + "/echo";
|
||||
|
||||
export function getHttpTransportTypes(): HttpTransportType[] {
|
||||
const transportTypes = [];
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
import { AbortError, DefaultHttpClient, HttpClient, HttpRequest, HttpResponse, HttpTransportType, HubConnection, HubConnectionBuilder, IHttpConnectionOptions, IStreamSubscriber, JsonHubProtocol, LogLevel } from "@aspnet/signalr";
|
||||
import { MessagePackHubProtocol } from "@aspnet/signalr-protocol-msgpack";
|
||||
|
||||
import { eachTransport, eachTransportAndProtocol } from "./Common";
|
||||
import { eachTransport, eachTransportAndProtocol, ENDPOINT_BASE_URL } from "./Common";
|
||||
import { TestLogger } from "./TestLogger";
|
||||
|
||||
const TESTHUBENDPOINT_URL = "/testhub";
|
||||
|
|
@ -345,7 +345,7 @@ describe("hubConnection", () => {
|
|||
});
|
||||
|
||||
it("closed with error if hub cannot be created", (done) => {
|
||||
const hubConnection = getConnectionBuilder(transportType, "http://" + document.location.host + "/uncreatable")
|
||||
const hubConnection = getConnectionBuilder(transportType, ENDPOINT_BASE_URL + "/uncreatable")
|
||||
.withHubProtocol(protocol)
|
||||
.build();
|
||||
|
||||
|
|
@ -496,7 +496,7 @@ describe("hubConnection", () => {
|
|||
const message = "你好,世界!";
|
||||
|
||||
try {
|
||||
const jwtToken = await getJwtToken("http://" + document.location.host + "/generateJwtToken");
|
||||
const jwtToken = await getJwtToken(ENDPOINT_BASE_URL + "/generateJwtToken");
|
||||
|
||||
const hubConnection = getConnectionBuilder(transportType, "/authorizedhub", {
|
||||
accessTokenFactory: () => jwtToken,
|
||||
|
|
@ -525,7 +525,7 @@ describe("hubConnection", () => {
|
|||
|
||||
try {
|
||||
const hubConnection = getConnectionBuilder(transportType, "/authorizedhub", {
|
||||
accessTokenFactory: () => getJwtToken("http://" + document.location.host + "/generateJwtToken"),
|
||||
accessTokenFactory: () => getJwtToken(ENDPOINT_BASE_URL + "/generateJwtToken"),
|
||||
}).build();
|
||||
|
||||
hubConnection.onclose((error) => {
|
||||
|
|
@ -573,6 +573,8 @@ describe("hubConnection", () => {
|
|||
|
||||
// Check what transport was used by asking the server to tell us.
|
||||
expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("ServerSentEvents");
|
||||
|
||||
await hubConnection.stop();
|
||||
done();
|
||||
} catch (e) {
|
||||
fail(e);
|
||||
|
|
@ -590,6 +592,8 @@ describe("hubConnection", () => {
|
|||
|
||||
// Check what transport was used by asking the server to tell us.
|
||||
expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("LongPolling");
|
||||
|
||||
await hubConnection.stop();
|
||||
done();
|
||||
} catch (e) {
|
||||
fail(e);
|
||||
|
|
@ -614,6 +618,7 @@ describe("hubConnection", () => {
|
|||
// Make sure that we connect with SSE or LongPolling after Websockets fail
|
||||
const transportName = await hubConnection.invoke("GetActiveTransportName");
|
||||
expect(transportName === "ServerSentEvents" || transportName === "LongPolling").toBe(true);
|
||||
await hubConnection.stop();
|
||||
} catch (e) {
|
||||
fail(e);
|
||||
} finally {
|
||||
|
|
@ -681,6 +686,8 @@ describe("hubConnection", () => {
|
|||
expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("LongPolling");
|
||||
// Check to see that the Content-Type header is set the expected value
|
||||
expect(await hubConnection.invoke("GetContentTypeHeader")).toEqual("text/plain;charset=UTF-8");
|
||||
|
||||
await hubConnection.stop();
|
||||
done();
|
||||
} catch (e) {
|
||||
fail(e);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,14 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SignalRSamples.ConnectionHandlers;
|
||||
using SignalRSamples.Hubs;
|
||||
|
||||
|
|
@ -62,6 +67,40 @@ namespace SignalRSamples
|
|||
{
|
||||
routes.MapConnectionHandler<MessagesConnectionHandler>("/chat");
|
||||
});
|
||||
|
||||
app.Use(next => (context) =>
|
||||
{
|
||||
if (context.Request.Path.StartsWithSegments("/deployment"))
|
||||
{
|
||||
var attributes = Assembly.GetAssembly(typeof(Startup)).GetCustomAttributes<AssemblyMetadataAttribute>();
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
using (var textWriter = new StreamWriter(context.Response.Body))
|
||||
using (var writer = new JsonTextWriter(textWriter))
|
||||
{
|
||||
var json = new JObject();
|
||||
var commitHash = string.Empty;
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
json.Add(attribute.Key, attribute.Value);
|
||||
|
||||
if (string.Equals(attribute.Key, "CommitHash"))
|
||||
{
|
||||
commitHash = attribute.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(commitHash))
|
||||
{
|
||||
json.Add("GitHubUrl", $"https://github.com/aspnet/SignalR/commit/{commitHash}");
|
||||
}
|
||||
|
||||
json.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,31 +11,16 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
|||
{
|
||||
public bool IsMet => CheckDocker();
|
||||
public string SkipReason { get; private set; } = "Docker is not available";
|
||||
public string RequiredOsType { get; }
|
||||
|
||||
public SkipIfDockerNotPresentAttribute() : this("linux")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SkipIfDockerNotPresentAttribute(string requiredOSType)
|
||||
{
|
||||
RequiredOsType = requiredOSType;
|
||||
}
|
||||
|
||||
private bool CheckDocker()
|
||||
{
|
||||
if(Docker.Default != null)
|
||||
{
|
||||
// Docker is present, but is it working?
|
||||
if (Docker.Default.RunCommand("info -f {{.OSType}}", out var output) != 0)
|
||||
if (Docker.Default.RunCommand("ps", out var output) != 0)
|
||||
{
|
||||
SkipReason = $"Failed to invoke test command 'docker ps'. Output: {output}";
|
||||
}
|
||||
else if (!string.Equals(output.Trim(), RequiredOsType, StringComparison.Ordinal))
|
||||
{
|
||||
SkipReason = $"Docker tests do not support the OS type '{output.Trim()}', they require '{RequiredOsType}'.";
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a docker
|
||||
|
|
|
|||
Loading…
Reference in New Issue