Don't allow empty list names (#1886)

This commit is contained in:
Charis Kyriakou
2022-12-19 11:59:53 +00:00
committed by GitHub
parent 2493ddd39a
commit 22ec4b0b6a
2 changed files with 33 additions and 0 deletions

View File

@@ -76,6 +76,10 @@ export class DbManager {
}
public async addNewRemoteList(listName: string): Promise<void> {
if (listName === "") {
throw Error("List name cannot be empty");
}
if (this.dbConfigStore.doesRemoteListExist(listName)) {
throw Error(`A list with the name '${listName}' already exists`);
}

View File

@@ -549,6 +549,35 @@ describe("db panel", () => {
);
});
describe("Name validation", () => {
it("should not allow adding a new list with empty name", async () => {
const dbConfig = createDbConfig();
await saveDbConfig(dbConfig);
await expect(dbManager.addNewRemoteList("")).rejects.toThrow(
new Error("List name cannot be empty"),
);
});
it("should not allow adding a list with duplicate name", async () => {
const dbConfig = createDbConfig({
remoteLists: [
{
name: "my-list-1",
repositories: ["owner1/repo1", "owner1/repo2"],
},
],
});
await saveDbConfig(dbConfig);
await expect(dbManager.addNewRemoteList("my-list-1")).rejects.toThrow(
new Error("A list with the name 'my-list-1' already exists"),
);
});
});
async function saveDbConfig(dbConfig: DbConfig): Promise<void> {
await writeJson(dbConfigFilePath, dbConfig);