Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Actor ID validation #539

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/actors/ActorId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default class ActorId {
private readonly id: string;

constructor(id: string) {
if(id==='') throw new Error("ActorId cannot be empty")
heunghingwan marked this conversation as resolved.
Show resolved Hide resolved
if (id.match(/\//)) throw new Error("ActorId cannot contain '/'");
this.id = id;
}

Expand Down
16 changes: 16 additions & 0 deletions test/e2e/http/actors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ describe("http/actors", () => {
});
});

describe("actorId", () => {
it("should be able to create an actorId", () => {
const actorId = ActorId.createRandomId();
expect(actorId.getId()).toBeDefined();
expect(actorId.toString()).toBeDefined();
});

it("should not be able to create an actorId with an empty string", () => {
expect(() => new ActorId("")).toThrowError("ActorId cannot be empty");
});

it("should not be able to create an actorId with a slash", () => {
expect(() => new ActorId("test/test")).toThrowError("ActorId cannot contain '/'");
});
})

describe("actorProxy", () => {
it("should be able to create an actor object through the proxy", async () => {
const builder = new ActorProxyBuilder<DemoActorCounterInterface>(DemoActorCounterImpl, client);
Expand Down