Skip to content

Commit

Permalink
URL enconding of AID alias name in rest calls (#233)
Browse files Browse the repository at this point in the history
* URL enconding of name in api call

* prettier

* content-lenght header not needed

* add test

* remove debris

* fix test

* pretty

* Update test/app/aiding.test.ts
  • Loading branch information
rodolfomiranda authored Apr 3, 2024
1 parent a49db7f commit ac6dac4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Identifier {
* @returns {Promise<any>} A promise to the identifier information
*/
async get(name: string): Promise<any> {
const path = `/identifiers/${name}`;
const path = `/identifiers/${encodeURIComponent(name)}`;
const data = null;
const method = 'GET';
const res = await this.client.fetch(path, method, data);
Expand Down
4 changes: 1 addition & 3 deletions src/keri/app/clienting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ export class SignifyClient {
headers.set('Content-Type', 'application/json');

const _body = method == 'GET' ? null : JSON.stringify(data);
if (_body !== null) {
headers.set('Content-Length', String(_body.length));
}

if (this.authn) {
signed_headers = this.authn.sign(
headers,
Expand Down
9 changes: 9 additions & 0 deletions test/app/aiding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ describe('Aiding', () => {
assert.deepEqual(lastCall.body.salty.transferable, true);
});

it('Can get identifiers with special characters in the name', async () => {
client.fetch.mockResolvedValue(Response.json({}));
await client.identifiers().get('a name with ñ!');

const lastCall = client.getLastMockRequest();
assert.equal(lastCall.method, 'GET');
assert.equal(lastCall.path, '/identifiers/a%20name%20with%20%C3%B1!');
});

it('Can create salty AID with multiple signatures', async () => {
client.fetch.mockResolvedValue(Response.json({}));

Expand Down

0 comments on commit ac6dac4

Please sign in to comment.