You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
[Backport staging] Fix POST data not being passed for registerWithIdentityServer (#2770)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -1254,6 +1254,20 @@ describe("MatrixClient", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("agreeToTerms", () => {
|
||||||
|
it("should send `user_accepts` via body of POST request", async () => {
|
||||||
|
const terms = ["https://vector.im/notice-1"];
|
||||||
|
|
||||||
|
httpBackend!.when("POST", "/terms").check(req => {
|
||||||
|
expect(req.data.user_accepts).toStrictEqual(terms);
|
||||||
|
}).respond(200, {});
|
||||||
|
|
||||||
|
const prom = client!.agreeToTerms(SERVICE_TYPES.IS, "https://vector.im", "at", terms);
|
||||||
|
await httpBackend!.flushAllExpected();
|
||||||
|
await prom;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("publicRooms", () => {
|
describe("publicRooms", () => {
|
||||||
it("should use GET request if no server or filter is specified", () => {
|
it("should use GET request if no server or filter is specified", () => {
|
||||||
httpBackend!.when("GET", "/publicRooms").respond(200, {});
|
httpBackend!.when("GET", "/publicRooms").respond(200, {});
|
||||||
@@ -1263,7 +1277,7 @@ describe("MatrixClient", function() {
|
|||||||
|
|
||||||
it("should use GET request if only server is specified", () => {
|
it("should use GET request if only server is specified", () => {
|
||||||
httpBackend!.when("GET", "/publicRooms").check(request => {
|
httpBackend!.when("GET", "/publicRooms").check(request => {
|
||||||
expect(request.queryParams.server).toBe("server1");
|
expect(request.queryParams?.server).toBe("server1");
|
||||||
}).respond(200, {});
|
}).respond(200, {});
|
||||||
client!.publicRooms({ server: "server1" });
|
client!.publicRooms({ server: "server1" });
|
||||||
return httpBackend!.flushAllExpected();
|
return httpBackend!.flushAllExpected();
|
||||||
@@ -1296,6 +1310,30 @@ describe("MatrixClient", function() {
|
|||||||
expect(client.http.opts.accessToken).toBe(token);
|
expect(client.http.opts.accessToken).toBe(token);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("registerWithIdentityServer", () => {
|
||||||
|
it("should pass data to POST request", async () => {
|
||||||
|
const token = {
|
||||||
|
access_token: "access_token",
|
||||||
|
token_type: "Bearer",
|
||||||
|
matrix_server_name: "server_name",
|
||||||
|
expires_in: 12345,
|
||||||
|
};
|
||||||
|
|
||||||
|
httpBackend!.when("POST", "/account/register").check(req => {
|
||||||
|
expect(req.data).toStrictEqual(token);
|
||||||
|
}).respond(200, {
|
||||||
|
access_token: "at",
|
||||||
|
token: "tt",
|
||||||
|
});
|
||||||
|
|
||||||
|
const prom = client!.registerWithIdentityServer(token);
|
||||||
|
await httpBackend!.flushAllExpected();
|
||||||
|
const resp = await prom;
|
||||||
|
expect(resp.access_token).toBe("at");
|
||||||
|
expect(resp.token).toBe("tt");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent {
|
function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent {
|
||||||
|
@@ -8278,13 +8278,16 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* Server access token.
|
* Server access token.
|
||||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||||
*/
|
*/
|
||||||
public registerWithIdentityServer(hsOpenIdToken: any): Promise<any> { // TODO: Types
|
public registerWithIdentityServer(hsOpenIdToken: IOpenIDToken): Promise<{
|
||||||
|
access_token: string;
|
||||||
|
token: string;
|
||||||
|
}> {
|
||||||
if (!this.idBaseUrl) {
|
if (!this.idBaseUrl) {
|
||||||
throw new Error("No identity server base URL set");
|
throw new Error("No identity server base URL set");
|
||||||
}
|
}
|
||||||
|
|
||||||
const uri = this.http.getUrl("/account/register", undefined, IdentityPrefix.V2, this.idBaseUrl);
|
const uri = this.http.getUrl("/account/register", undefined, IdentityPrefix.V2, this.idBaseUrl);
|
||||||
return this.http.requestOtherUrl(Method.Post, uri, null, hsOpenIdToken);
|
return this.http.requestOtherUrl(Method.Post, uri, hsOpenIdToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8751,15 +8754,14 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
termsUrls: string[],
|
termsUrls: string[],
|
||||||
): Promise<any> { // TODO: Types
|
): Promise<{}> {
|
||||||
const url = this.termsUrlForService(serviceType, baseUrl);
|
const url = this.termsUrlForService(serviceType, baseUrl);
|
||||||
utils.encodeParams({
|
|
||||||
user_accepts: termsUrls,
|
|
||||||
}, url.searchParams);
|
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: "Bearer " + accessToken,
|
Authorization: "Bearer " + accessToken,
|
||||||
};
|
};
|
||||||
return this.http.requestOtherUrl(Method.Post, url, null, { headers });
|
return this.http.requestOtherUrl(Method.Post, url, {
|
||||||
|
user_accepts: termsUrls,
|
||||||
|
}, { headers });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user