Browse Source

fix authorization hierarchy in postman import (#4686)

Co-authored-by: nivedin <nivedinp@gmail.com>
Anwarul Islam 1 month ago
parent
commit
fa1159da53

+ 10 - 5
packages/hoppscotch-common/src/helpers/import-export/import/postman.ts

@@ -197,12 +197,17 @@ type PMRequestAuthDef<
 const getVariableValue = (defs: VariableDefinition[], key: string) =>
   defs.find((param) => param.key === key)?.value as string | undefined
 
-const getHoppReqAuth = (hoppAuth: Item["request"]["auth"]): HoppRESTAuth => {
-  if (!hoppAuth) return { authType: "none", authActive: true }
+const getHoppReqAuth = (
+  hoppAuth: Item["request"]["auth"] | null
+): HoppRESTAuth => {
+  if (!hoppAuth) return { authType: "inherit", authActive: false }
 
-  // Cast to the type for more stricter checking down the line
   const auth = hoppAuth as unknown as PMRequestAuthDef
 
+  if (auth.type === "noauth") {
+    return { authType: "none", authActive: true }
+  }
+
   if (auth.type === "basic") {
     return {
       authType: "basic",
@@ -269,7 +274,7 @@ const getHoppReqAuth = (hoppAuth: Item["request"]["auth"]): HoppRESTAuth => {
     }
   }
 
-  return { authType: "none", authActive: true }
+  return { authType: "inherit", authActive: true }
 }
 
 const getHoppReqBody = ({
@@ -413,7 +418,7 @@ const getHoppFolder = (ig: ItemGroup<Item>): HoppCollection =>
       A.map(getHoppFolder)
     ),
     requests: pipe(ig.items.all(), A.filter(isPMItem), A.map(getHoppRequest)),
-    auth: { authType: "inherit", authActive: true },
+    auth: getHoppReqAuth(ig.auth),
     headers: [],
   })