Skip to content

Commit

Permalink
tests: add unauthenticated user token lookup test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jan 25, 2024
1 parent d57e1e2 commit 41317c9
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions test/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as grpc from '@grpc/grpc-js';
import { updateConfig } from '@restorecommerce/acs-client';
import {
UserServiceDefinition,
UserServiceClient, User, DeepPartial
UserServiceClient, User, DeepPartial, UserType
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/user';
import {
RoleServiceDefinition,
Expand Down Expand Up @@ -1826,6 +1826,75 @@ describe('testing identity-srv', () => {
await userService.unregister({ identifier: 'test.user1' });
});
});

describe('testing unauthenticated users', function registerUser(): void {
it('should create unauthenticated users and retrieve their tokens', async () => {
const aaaa = await userService.create({items: [
{
id: 'example-unauthenticated-user',
active: true,
user_type: UserType.TECHNICAL_USER,
name: 'exampleuser',
email: '[email protected]',
first_name: 'unauthenticated',
last_name: 'unauthenticated',
properties: [
{
id: 'urn:restorecommerce:acs:names:network:src:domain',
value: 'example.com'
}
],
tokens: [
{
name: 'unauthenticated_token',
token: 'aaaa'
}
]
},
{
id: 'foo-unauthenticated-user',
active: true,
user_type: UserType.TECHNICAL_USER,
name: 'unauthenticated',
email: '[email protected]',
first_name: 'unauthenticated',
last_name: 'unauthenticated',
properties: [
{
id: 'urn:restorecommerce:acs:names:network:src:domain',
value: 'foo.com'
}
],
tokens: [
{
name: 'unauthenticated_token',
token: 'bbbb'
}
]
}
]});

const exampleToken = await userService.getUnauthenticatedSubjectTokenForTenant({
domain: 'example.com'
});

exampleToken.token.should.equal('aaaa');

const fooToken = await userService.getUnauthenticatedSubjectTokenForTenant({
domain: 'foo.com'
});

fooToken.token.should.equal('bbbb');

const missingToken = await userService.getUnauthenticatedSubjectTokenForTenant({
domain: 'hello.com'
});

missingToken.should.deepEqual({});

await userService.delete({ ids: ['example-unauthenticated-user', 'foo-unauthenticated-user'] });
});
});
});
});
});
});

0 comments on commit 41317c9

Please sign in to comment.