Skip to content

Commit 63f4bf5

Browse files
RiotRobott3chguy
andauthored
[Backport staging] Fix POST data not being passed for registerWithIdentityServer (matrix-org#2770)
Co-authored-by: Michael Telatynski <[email protected]>
1 parent fc1b03c commit 63f4bf5

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

spec/integ/matrix-client-methods.spec.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,20 @@ describe("MatrixClient", function() {
12541254
});
12551255
});
12561256

1257+
describe("agreeToTerms", () => {
1258+
it("should send `user_accepts` via body of POST request", async () => {
1259+
const terms = ["https://vector.im/notice-1"];
1260+
1261+
httpBackend!.when("POST", "/terms").check(req => {
1262+
expect(req.data.user_accepts).toStrictEqual(terms);
1263+
}).respond(200, {});
1264+
1265+
const prom = client!.agreeToTerms(SERVICE_TYPES.IS, "https://vector.im", "at", terms);
1266+
await httpBackend!.flushAllExpected();
1267+
await prom;
1268+
});
1269+
});
1270+
12571271
describe("publicRooms", () => {
12581272
it("should use GET request if no server or filter is specified", () => {
12591273
httpBackend!.when("GET", "/publicRooms").respond(200, {});
@@ -1263,7 +1277,7 @@ describe("MatrixClient", function() {
12631277

12641278
it("should use GET request if only server is specified", () => {
12651279
httpBackend!.when("GET", "/publicRooms").check(request => {
1266-
expect(request.queryParams.server).toBe("server1");
1280+
expect(request.queryParams?.server).toBe("server1");
12671281
}).respond(200, {});
12681282
client!.publicRooms({ server: "server1" });
12691283
return httpBackend!.flushAllExpected();
@@ -1296,6 +1310,30 @@ describe("MatrixClient", function() {
12961310
expect(client.http.opts.accessToken).toBe(token);
12971311
});
12981312
});
1313+
1314+
describe("registerWithIdentityServer", () => {
1315+
it("should pass data to POST request", async () => {
1316+
const token = {
1317+
access_token: "access_token",
1318+
token_type: "Bearer",
1319+
matrix_server_name: "server_name",
1320+
expires_in: 12345,
1321+
};
1322+
1323+
httpBackend!.when("POST", "/account/register").check(req => {
1324+
expect(req.data).toStrictEqual(token);
1325+
}).respond(200, {
1326+
access_token: "at",
1327+
token: "tt",
1328+
});
1329+
1330+
const prom = client!.registerWithIdentityServer(token);
1331+
await httpBackend!.flushAllExpected();
1332+
const resp = await prom;
1333+
expect(resp.access_token).toBe("at");
1334+
expect(resp.token).toBe("tt");
1335+
});
1336+
});
12991337
});
13001338

13011339
function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent {

src/client.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8278,13 +8278,16 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
82788278
* Server access token.
82798279
* @return {module:http-api.MatrixError} Rejects: with an error response.
82808280
*/
8281-
public registerWithIdentityServer(hsOpenIdToken: any): Promise<any> { // TODO: Types
8281+
public registerWithIdentityServer(hsOpenIdToken: IOpenIDToken): Promise<{
8282+
access_token: string;
8283+
token: string;
8284+
}> {
82828285
if (!this.idBaseUrl) {
82838286
throw new Error("No identity server base URL set");
82848287
}
82858288

82868289
const uri = this.http.getUrl("/account/register", undefined, IdentityPrefix.V2, this.idBaseUrl);
8287-
return this.http.requestOtherUrl(Method.Post, uri, null, hsOpenIdToken);
8290+
return this.http.requestOtherUrl(Method.Post, uri, hsOpenIdToken);
82888291
}
82898292

82908293
/**
@@ -8751,15 +8754,14 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
87518754
baseUrl: string,
87528755
accessToken: string,
87538756
termsUrls: string[],
8754-
): Promise<any> { // TODO: Types
8757+
): Promise<{}> {
87558758
const url = this.termsUrlForService(serviceType, baseUrl);
8756-
utils.encodeParams({
8757-
user_accepts: termsUrls,
8758-
}, url.searchParams);
87598759
const headers = {
87608760
Authorization: "Bearer " + accessToken,
87618761
};
8762-
return this.http.requestOtherUrl(Method.Post, url, null, { headers });
8762+
return this.http.requestOtherUrl(Method.Post, url, {
8763+
user_accepts: termsUrls,
8764+
}, { headers });
87638765
}
87648766

87658767
/**

0 commit comments

Comments
 (0)