[ARVADOS-WORKBENCH2] created: 2.1.0-210-g0429d378

Git user git at public.arvados.org
Fri Feb 19 20:29:16 UTC 2021


        at  0429d37860f633725ecff6bd923e196a61121881 (commit)


commit 0429d37860f633725ecff6bd923e196a61121881
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Fri Feb 19 17:28:20 2021 -0300

    17319: Throws exceptions when attempting to use "" as uuid on service calls.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>

diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts
index 8e00c4ad..54c0edf6 100644
--- a/src/services/common-service/common-service.ts
+++ b/src/services/common-service/common-service.ts
@@ -68,6 +68,12 @@ export class CommonService<T> {
             }
         }
 
+    private validateUuid(uuid: string) {
+        if (uuid === "") {
+            throw new Error('UUID cannot be empty string');
+        }
+    }
+
     static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions, mapKeys = true, showErrors = true): Promise<R> {
         const reqId = uuid();
         actions.progressFn(reqId, true);
@@ -97,6 +103,7 @@ export class CommonService<T> {
     }
 
     delete(uuid: string): Promise<T> {
+        this.validateUuid(uuid);
         return CommonService.defaultResponse(
             this.serverApi
                 .delete(this.resourceType + '/' + uuid),
@@ -105,6 +112,7 @@ export class CommonService<T> {
     }
 
     get(uuid: string, showErrors?: boolean) {
+        this.validateUuid(uuid);
         return CommonService.defaultResponse(
             this.serverApi
                 .get<T>(this.resourceType + '/' + uuid),
@@ -148,6 +156,7 @@ export class CommonService<T> {
     }
 
     update(uuid: string, data: Partial<T>) {
+        this.validateUuid(uuid);
         return CommonService.defaultResponse(
             this.serverApi
                 .put<T>(this.resourceType + '/' + uuid, data && CommonService.mapKeys(_.snakeCase)(data)),

commit 1301bb460ffc3e8d179492a08dbdb3a67aa080f8
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Fri Feb 19 17:27:37 2021 -0300

    17319: Adds tests exposing the bug.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>

diff --git a/src/services/common-service/common-resource-service.test.ts b/src/services/common-service/common-resource-service.test.ts
index 038c6943..d00412b8 100644
--- a/src/services/common-service/common-resource-service.test.ts
+++ b/src/services/common-service/common-resource-service.test.ts
@@ -15,12 +15,11 @@ const actions: ApiActions = {
 
 export const mockResourceService = <R extends Resource, C extends CommonResourceService<R>>(
     Service: new (client: AxiosInstance, actions: ApiActions) => C) => {
-    const axiosInstance = axios.create();
-    const axiosMock = new MockAdapter(axiosInstance);
-    const service = new Service(axiosInstance, actions);
-    Object.keys(service).map(key => service[key] = jest.fn());
-    return service;
-};
+        const axiosInstance = axios.create();
+        const service = new Service(axiosInstance, actions);
+        Object.keys(service).map(key => service[key] = jest.fn());
+        return service;
+    };
 
 describe("CommonResourceService", () => {
     let axiosInstance: AxiosInstance;
diff --git a/src/services/common-service/common-service.test.ts b/src/services/common-service/common-service.test.ts
new file mode 100644
index 00000000..db36570a
--- /dev/null
+++ b/src/services/common-service/common-service.test.ts
@@ -0,0 +1,30 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import axios from "axios";
+import { ApiActions } from "~/services/api/api-actions";
+import { CommonService } from "./common-service";
+
+const actions: ApiActions = {
+    progressFn: (id: string, working: boolean) => {},
+    errorFn: (id: string, message: string) => {}
+};
+
+describe("CommonService", () => {
+    const axiosInstance = axios.create();
+    // const axiosMock = new MockAdapter(axiosInstance);
+    const commonService = new CommonService(axiosInstance, "resource", actions);
+
+    it("throws an exception when passing uuid as empty string to get()", () => {
+        expect(() => commonService.get("")).toThrowError("UUID cannot be empty string");
+    });
+
+    it("throws an exception when passing uuid as empty string to update()", () => {
+        expect(() => commonService.update("", {})).toThrowError("UUID cannot be empty string");
+    });
+
+    it("throws an exception when passing uuid as empty string to delete()", () => {
+        expect(() => commonService.delete("")).toThrowError("UUID cannot be empty string");
+    });
+});
\ No newline at end of file

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list