Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

fix #1155 by renaming signalRTokenHeader to access_token (#1343) #1359

Merged
merged 1 commit into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client-ts/FunctionalTests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public void ConfigureServices(IServiceCollection services)
{
OnMessageReceived = context =>
{
var signalRTokenHeader = context.Request.Query["signalRTokenHeader"];
var signalRTokenHeader = context.Request.Query["access_token"];

if (!string.IsNullOrEmpty(signalRTokenHeader) &&
(context.HttpContext.WebSockets.IsWebSocketRequest || context.Request.Headers["Accept"] == "text/event-stream"))
{
context.Token = context.Request.Query["signalRTokenHeader"];
context.Token = context.Request.Query["access_token"];
}
return Task.CompletedTask;
}
Expand Down
2 changes: 1 addition & 1 deletion client-ts/FunctionalTests/ts/HubConnectionTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ describe('hubConnection', function () {
hubConnection = new HubConnection('/authorizedhub', {
transport: transportType,
logger: LogLevel.Trace,
accessToken: () => jwtToken
accessTokenFactory: () => jwtToken
});
hubConnection.onclose(function (error) {
expect(error).toBe(undefined);
Expand Down
30 changes: 17 additions & 13 deletions client-ts/signalr/spec/HttpConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ import { ITransport, TransportType, TransferMode } from "../src/Transports"
import { eachTransport, eachEndpointUrl } from "./Common";
import { HttpResponse } from "../src/index";

const commonOptions: IHttpConnectionOptions = {
logger: null
};

describe("HttpConnection", () => {
it("cannot be created with relative url if document object is not present", () => {
expect(() => new HttpConnection("/test"))
expect(() => new HttpConnection("/test", commonOptions))
.toThrow(new Error("Cannot resolve '/test'."));
});

it("cannot be created with relative url if window object is not present", () => {
(<any>global).window = {};
expect(() => new HttpConnection("/test"))
expect(() => new HttpConnection("/test", commonOptions))
.toThrow(new Error("Cannot resolve '/test'."));
delete (<any>global).window;
});

it("starting connection fails if getting id fails", async (done) => {
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => Promise.reject("error"))
.on("GET", r => ""),
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand All @@ -45,6 +49,7 @@ describe("HttpConnection", () => {

it("cannot start a running connection", async (done) => {
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => {
connection.start()
Expand All @@ -58,7 +63,6 @@ describe("HttpConnection", () => {
});
return Promise.reject("error");
}),
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand All @@ -75,13 +79,13 @@ describe("HttpConnection", () => {
it("can start a stopped connection", async (done) => {
let negotiateCalls = 0;
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => {
negotiateCalls += 1;
return Promise.reject("reached negotiate");
})
.on("GET", r => ""),
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand All @@ -103,6 +107,7 @@ describe("HttpConnection", () => {

it("can stop a starting connection", async (done) => {
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => {
connection.stop();
Expand All @@ -112,7 +117,6 @@ describe("HttpConnection", () => {
connection.stop();
return "";
}),
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand All @@ -128,7 +132,7 @@ describe("HttpConnection", () => {
});

it("can stop a non-started connection", async (done) => {
let connection = new HttpConnection("http://tempuri.org");
let connection = new HttpConnection("http://tempuri.org", commonOptions);
await connection.stop();
done();
});
Expand All @@ -151,11 +155,11 @@ describe("HttpConnection", () => {
}

let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => "{ \"connectionId\": \"42\" }")
.on("GET", r => ""),
transport: fakeTransport,
logger: null,
} as IHttpConnectionOptions;


Expand All @@ -178,6 +182,7 @@ describe("HttpConnection", () => {
let negotiateUrl: string;
let connection: HttpConnection;
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => {
negotiateUrl = r.url;
Expand All @@ -188,7 +193,6 @@ describe("HttpConnection", () => {
connection.stop();
return "";
}),
logger: null
} as IHttpConnectionOptions;

connection = new HttpConnection(givenUrl, options);
Expand All @@ -212,11 +216,11 @@ describe("HttpConnection", () => {
}
it(`cannot be started if requested ${TransportType[requestedTransport]} transport not available on server`, async done => {
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => "{ \"connectionId\": \"42\", \"availableTransports\": [] }")
.on("GET", r => ""),
transport: requestedTransport,
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand All @@ -234,10 +238,10 @@ describe("HttpConnection", () => {

it("cannot be started if no transport available on server and no transport requested", async done => {
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => "{ \"connectionId\": \"42\", \"availableTransports\": [] }")
.on("GET", r => ""),
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand All @@ -254,9 +258,9 @@ describe("HttpConnection", () => {

it('does not send negotiate request if WebSockets transport requested explicitly', async done => {
let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient(),
transport: TransportType.WebSockets,
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("http://tempuri.org", options);
Expand Down Expand Up @@ -291,11 +295,11 @@ describe("HttpConnection", () => {
} as ITransport;

let options: IHttpConnectionOptions = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", r => "{ \"connectionId\": \"42\", \"availableTransports\": [] }")
.on("GET", r => ""),
transport: fakeTransport,
logger: null
} as IHttpConnectionOptions;

let connection = new HttpConnection("https://tempuri.org", options);
Expand Down
Loading