Skip to content

Commit

Permalink
Merge branch 'main' into importing-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole authored Jan 14, 2024
2 parents 62d9375 + d669f1b commit 0baa433
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 140 deletions.
1 change: 0 additions & 1 deletion application/frontend/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const SUBSECTION = '/subsection';
export const SEARCH = '/search';
export const CRE = '/cre';
export const GRAPH = '/graph';
export const DEEPLINK = '/deeplink';
export const BROWSEROOT = '/root_cres';
export const GAP_ANALYSIS = '/map_analysis';
export const EXPLORER = '/explorer';
Expand Down
90 changes: 0 additions & 90 deletions application/frontend/src/pages/Deeplink/Deeplink.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions application/frontend/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ReactNode } from 'react';
import {
BROWSEROOT,
CRE,
DEEPLINK,
EXPLORER,
GAP_ANALYSIS,
GRAPH,
Expand All @@ -16,7 +15,6 @@ import {
import { CommonRequirementEnumeration, Graph, Search, Standard } from './pages';
import { BrowseRootCres } from './pages/BrowseRootCres/browseRootCres';
import { Chatbot } from './pages/chatbot/chatbot';
import { Deeplink } from './pages/Deeplink/Deeplink';
import { Explorer } from './pages/Explorer/explorer';
import { ExplorerCircles } from './pages/Explorer/visuals/circles/circles';
import { ExplorerForceGraph } from './pages/Explorer/visuals/force-graph/forceGraph';
Expand Down Expand Up @@ -81,36 +79,6 @@ export const ROUTES: IRoute[] = [
showHeader: true,
showFilter: true,
},
{
path: `${DEEPLINK}/node/:type/:nodeName/section/:section`,
component: Deeplink,
showHeader: true,
showFilter: false,
},
{
path: `${DEEPLINK}/node/:type/:nodeName/section/:section/subsection/:subsection`,
component: Deeplink,
showHeader: true,
showFilter: false,
},
{
path: `${DEEPLINK}/node/:type/:nodeName/tooltype/:tooltype`,
component: Deeplink,
showHeader: true,
showFilter: false,
},
{
path: `${DEEPLINK}/node/:type/:nodeName`,
component: Deeplink,
showHeader: true,
showFilter: false,
},
{
path: `${DEEPLINK}/:nodeName`,
component: Deeplink,
showHeader: true,
showFilter: false,
},
{
path: `/chatbot`,
component: Chatbot,
Expand Down
84 changes: 69 additions & 15 deletions application/tests/web_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ def test_deeplink(self) -> None:
)
self.assertEqual(404, response.status_code)

response = client.get(
f"/deeplink/{''.join(random.choice(string.ascii_letters) for i in range(10))}",
)
self.assertEqual(404, response.status_code)

response = client.get(
f"/deeplink/standard/{''.join(random.choice(string.ascii_letters) for i in range(10))}",
)
self.assertEqual(404, response.status_code)

cres = {
"ca": defs.CRE(id="1", description="CA", name="CA", tags=["ta"]),
"cd": defs.CRE(id="2", description="CD", name="CD", tags=["td"]),
Expand Down Expand Up @@ -771,38 +781,82 @@ def test_deeplink(self) -> None:
response = client.get("/rest/v1/deeplink/CWE?sectionid=456")
self.assertEqual(404, response.status_code)

# rest/v1 path works
response = client.get("/rest/v1/deeplink/ASVS?sectionid=v0.1.2")
location = ""
for head in response.headers:
if head[0] == "Location":
location = head[1]
self.assertEqual(location, standards["ASVS"].hyperlink)
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

response = client.get("/rest/v1/deeplink/ASVS?sectionID=v0.1.2")
location = ""
# Can retrieve with sectionid
response = client.get("/deeplink/ASVS?sectionid=v0.1.2")
for head in response.headers:
if head[0] == "Location":
location = head[1]
self.assertEqual(location, standards["ASVS"].hyperlink)
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with sectionID
response = client.get("/deeplink/ASVS?sectionID=v0.1.2")
for head in response.headers:
if head[0] == "Location":
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with section
response = client.get(f'/deeplink/ASVS?section={standards["ASVS"].section}')
for head in response.headers:
if head[0] == "Location":
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with section and sectionID/sectionid
response = client.get(
f'/rest/v1/deeplink/ASVS?section={standards["ASVS"].section}'
f'/deeplink/ASVS?section={standards["ASVS"].section}&sectionID={standards["ASVS"].sectionID}'
)
location = ""
for head in response.headers:
if head[0] == "Location":
location = head[1]
self.assertEqual(location, standards["ASVS"].hyperlink)
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with sectionid in path params
response = client.get(
f'/rest/v1/deeplink/ASVS?section={standards["ASVS"].section}&sectionID={standards["ASVS"].sectionID}'
f'/deeplink/ASVS/sectionid/{standards["ASVS"].sectionID}'
)
location = ""
for head in response.headers:
if head[0] == "Location":
location = head[1]
self.assertEqual(location, standards["ASVS"].hyperlink)
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with sectionID in path params
response = client.get(
f'/deeplink/ASVS/sectionID/{standards["ASVS"].sectionID}'
)
for head in response.headers:
if head[0] == "Location":
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with section in path params
response = client.get(f'/deeplink/ASVS/section/{standards["ASVS"].section}')
for head in response.headers:
if head[0] == "Location":
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with section and sectionid in path params
response = client.get(
f'/deeplink/ASVS/section/{standards["ASVS"].section}/sectionid/{standards["ASVS"].sectionID}'
)
for head in response.headers:
if head[0] == "Location":
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)

# Can retrieve with section and sectionID in path params
response = client.get(
f'/deeplink/ASVS/section/{standards["ASVS"].section}/sectionID/{standards["ASVS"].sectionID}'
)
for head in response.headers:
if head[0] == "Location":
self.assertEqual(head[1], standards["ASVS"].hyperlink)
self.assertEqual(302, response.status_code)
18 changes: 16 additions & 2 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,16 @@ def smartlink(

@app.route("/rest/v1/deeplink/<ntype>/<name>", methods=["GET"])
@app.route("/rest/v1/deeplink/<name>", methods=["GET"])
def deeplink(name: str, ntype: str = "") -> Any:
@app.route("/deeplink/<ntype>/<name>", methods=["GET"])
@app.route("/deeplink/<name>", methods=["GET"])
@app.route("/deeplink/<name>/section/<section>", methods=["GET"])
@app.route("/deeplink/<name>/section/<section>/sectionid/<section_id>", methods=["GET"])
@app.route("/deeplink/<name>/section/<section>/sectionID/<section_id>", methods=["GET"])
@app.route("/deeplink/<name>/sectionid/<section_id>", methods=["GET"])
@app.route("/deeplink/<name>/sectionID/<section_id>", methods=["GET"])
def deeplink(
name: str, ntype: str = "", section: str = "", section_id: str = ""
) -> Any:
database = db.Node_collection()
opt_section = request.args.get("section")
opt_sectionID = request.args.get("sectionID")
Expand All @@ -528,10 +537,15 @@ def deeplink(name: str, ntype: str = "") -> Any:

if opt_section:
opt_section = urllib.parse.unquote(opt_section)
elif section:
opt_section = urllib.parse.unquote(section)

if opt_sectionID:
opt_sectionID = urllib.parse.unquote(opt_sectionID)
elif opt_sectionid:
opt_sectionID = urllib.parse.unquote(opt_sectionid)
elif section_id:
opt_sectionID = urllib.parse.unquote(section_id)

nodes = None
nodes = database.get_nodes(
Expand All @@ -543,7 +557,7 @@ def deeplink(name: str, ntype: str = "") -> Any:
)
for node in nodes:
if len(node.hyperlink) > 0:
return redirect(node.hyperlink)
return redirect(location=node.hyperlink)

return abort(404)

Expand Down

0 comments on commit 0baa433

Please sign in to comment.