Skip to content

Commit 5a1991b

Browse files
committed
Added test cases for react-relay functions that retrieve data
1 parent 89040d0 commit 5a1991b

File tree

2 files changed

+158
-25
lines changed

2 files changed

+158
-25
lines changed
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#select
22
| test.jsx:27:29:27:32 | data | test.jsx:5:28:5:63 | fetch(" ... ntent") | test.jsx:27:29:27:32 | data | Cross-site scripting vulnerability due to $@. | test.jsx:5:28:5:63 | fetch(" ... ntent") | user-provided value |
3-
| testReactRelay.tsx:19:47:19:62 | commentData.text | testReactRelay.tsx:5:23:13:3 | useFrag ... Ref\\n ) | testReactRelay.tsx:19:47:19:62 | commentData.text | Cross-site scripting vulnerability due to $@. | testReactRelay.tsx:5:23:13:3 | useFrag ... Ref\\n ) | user-provided value |
3+
| testReactRelay.tsx:7:43:7:58 | commentData.text | testReactRelay.tsx:5:23:5:52 | useFrag ... entRef) | testReactRelay.tsx:7:43:7:58 | commentData.text | Cross-site scripting vulnerability due to $@. | testReactRelay.tsx:5:23:5:52 | useFrag ... entRef) | user-provided value |
44
edges
55
| test.jsx:5:11:5:63 | response | test.jsx:6:24:6:31 | response | provenance | |
66
| test.jsx:5:22:5:63 | await f ... ntent") | test.jsx:5:11:5:63 | response | provenance | |
@@ -11,9 +11,9 @@ edges
1111
| test.jsx:6:24:6:38 | response.json() | test.jsx:6:18:6:38 | await r ... .json() | provenance | |
1212
| test.jsx:7:12:7:15 | data | test.jsx:15:11:17:5 | data | provenance | |
1313
| test.jsx:15:11:17:5 | data | test.jsx:27:29:27:32 | data | provenance | |
14-
| testReactRelay.tsx:5:9:13:3 | commentData | testReactRelay.tsx:19:47:19:57 | commentData | provenance | |
15-
| testReactRelay.tsx:5:23:13:3 | useFrag ... Ref\\n ) | testReactRelay.tsx:5:9:13:3 | commentData | provenance | |
16-
| testReactRelay.tsx:19:47:19:57 | commentData | testReactRelay.tsx:19:47:19:62 | commentData.text | provenance | |
14+
| testReactRelay.tsx:5:9:5:52 | commentData | testReactRelay.tsx:7:43:7:53 | commentData | provenance | |
15+
| testReactRelay.tsx:5:23:5:52 | useFrag ... entRef) | testReactRelay.tsx:5:9:5:52 | commentData | provenance | |
16+
| testReactRelay.tsx:7:43:7:53 | commentData | testReactRelay.tsx:7:43:7:58 | commentData.text | provenance | |
1717
nodes
1818
| test.jsx:5:11:5:63 | response | semmle.label | response |
1919
| test.jsx:5:22:5:63 | await f ... ntent") | semmle.label | await f ... ntent") |
@@ -25,8 +25,26 @@ nodes
2525
| test.jsx:7:12:7:15 | data | semmle.label | data |
2626
| test.jsx:15:11:17:5 | data | semmle.label | data |
2727
| test.jsx:27:29:27:32 | data | semmle.label | data |
28-
| testReactRelay.tsx:5:9:13:3 | commentData | semmle.label | commentData |
29-
| testReactRelay.tsx:5:23:13:3 | useFrag ... Ref\\n ) | semmle.label | useFrag ... Ref\\n ) |
30-
| testReactRelay.tsx:19:47:19:57 | commentData | semmle.label | commentData |
31-
| testReactRelay.tsx:19:47:19:62 | commentData.text | semmle.label | commentData.text |
28+
| testReactRelay.tsx:5:9:5:52 | commentData | semmle.label | commentData |
29+
| testReactRelay.tsx:5:23:5:52 | useFrag ... entRef) | semmle.label | useFrag ... entRef) |
30+
| testReactRelay.tsx:7:43:7:53 | commentData | semmle.label | commentData |
31+
| testReactRelay.tsx:7:43:7:58 | commentData.text | semmle.label | commentData.text |
3232
subpaths
33+
testFailures
34+
| testReactRelay.tsx:17:45:17:64 | // $ Missing: Source | Missing result: Source |
35+
| testReactRelay.tsx:18:77:18:95 | // $ Missing: Alert | Missing result: Alert |
36+
| testReactRelay.tsx:28:70:28:88 | // $ Missing: Alert | Missing result: Alert |
37+
| testReactRelay.tsx:37:43:37:62 | // $ Missing: Source | Missing result: Source |
38+
| testReactRelay.tsx:38:61:38:79 | // $ Missing: Alert | Missing result: Alert |
39+
| testReactRelay.tsx:44:73:44:92 | // $ Missing: Source | Missing result: Source |
40+
| testReactRelay.tsx:47:57:47:75 | // $ Missing: Alert | Missing result: Alert |
41+
| testReactRelay.tsx:69:41:69:60 | // $ Missing: Source | Missing result: Source |
42+
| testReactRelay.tsx:70:61:70:79 | // $ Missing: Alert | Missing result: Alert |
43+
| testReactRelay.tsx:82:25:82:44 | // $ Missing: Source | Missing result: Source |
44+
| testReactRelay.tsx:87:71:87:89 | // $ Missing: Alert | Missing result: Alert |
45+
| testReactRelay.tsx:99:24:99:43 | // $ Missing: Source | Missing result: Source |
46+
| testReactRelay.tsx:112:68:112:86 | // $ Missing: Alert | Missing result: Alert |
47+
| testReactRelay.tsx:123:23:123:42 | // $ Missing: Source | Missing result: Source |
48+
| testReactRelay.tsx:126:46:126:64 | // $ Missing: Alert | Missing result: Alert |
49+
| testReactRelay.tsx:135:42:135:61 | // $ Missing: Source | Missing result: Source |
50+
| testReactRelay.tsx:136:63:136:81 | // $ Missing: Alert | Missing result: Alert |
Lines changed: 132 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,137 @@
1-
import React from 'react';
1+
import React, { useState } from "react";
22
import { useFragment } from 'react-relay';
33

4-
const CommentComponent = ({ commentRef }) => {
5-
const commentData = useFragment(
6-
graphql`
7-
fragment CommentComponent_comment on Comment {
8-
id
9-
text
10-
}
11-
`,
12-
commentRef
13-
); // $ Source=[js/xss]
4+
const func1 = ({ commentRef, query }) => {
5+
const commentData = useFragment(query, commentRef); // $ Source=[js/xss]
6+
return (
7+
<p dangerouslySetInnerHTML={{ __html: commentData.text }}> // $ Alert=[js/xss]
8+
{" "}
9+
{commentData.text}
10+
</p>
11+
);
12+
};
13+
14+
import { useLazyLoadQuery } from "react-relay";
1415

16+
function func2({ query }) {
17+
const data = useLazyLoadQuery(query, {}); // $ Missing: Source
18+
return <p dangerouslySetInnerHTML={{ __html: data.comments[0].text }} />; // $ Missing: Alert
19+
}
20+
21+
import { useQueryLoader, usePreloadedQuery } from "react-relay";
22+
23+
function func3({ initialQueryRef, query }) {
24+
const [queryReference, loadQuery] = useQueryLoader(query, initialQueryRef);
1525
return (
16-
<div>
17-
<h3>Comment:</h3>
18-
{/* Directly rendering user input without sanitation */}
19-
<p dangerouslySetInnerHTML = {{ __html: commentData.text}}> {commentData.text}</p> // $ Alert=[js/xss]
20-
</div>
26+
<h1
27+
dangerouslySetInnerHTML={{
28+
__html: usePreloadedQuery(query, queryReference).user?.name, // $ Missing: Alert
29+
}}
30+
/>
31+
);
32+
}
33+
34+
import { useClientQuery } from "react-relay";
35+
36+
function func4({ query }) {
37+
const data = useClientQuery(query, {}); // $ Missing: Source
38+
return <h1 dangerouslySetInnerHTML={{ __html: data }} />; // $ Missing: Alert
39+
}
40+
41+
import { useRefetchableFragment } from "react-relay";
42+
43+
function func5({ query, props }) {
44+
const [data, refetch] = useRefetchableFragment(query, props.comment); // $ Missing: Source
45+
return (
46+
<>
47+
<h1 dangerouslySetInnerHTML={{ __html: data }} /> // $ Missing: Alert
48+
<Button
49+
onClick={() => {
50+
refetch({ lang: "SPANISH" }, { fetchPolicy: "store-or-network" });
51+
}}
52+
></Button>
53+
</>
2154
);
22-
};
55+
}
56+
57+
import { usePaginationFragment } from "react-relay";
58+
59+
function func6({ query }) {
60+
const {
61+
data,
62+
loadNext,
63+
loadPrevious,
64+
hasNext,
65+
hasPrevious,
66+
isLoadingNext,
67+
isLoadingPrevious,
68+
refetch,
69+
} = usePaginationFragment(query, {}); // $ Missing: Source
70+
return <h1 dangerouslySetInnerHTML={{ __html: data }} />; // $ Missing: Alert
71+
}
72+
73+
74+
import { useMutation } from 'react-relay';
75+
import type { FeedbackLikeMutation } from './FeedbackLikeMutation.graphql';
76+
77+
function func7(query) {
78+
const [commit, inFlight] = useMutation<FeedbackLikeMutation>(query);
79+
const [feedbackText, setFeedbackText] = useState('');
80+
81+
commit({
82+
onCompleted(data) { // $ Missing: Source
83+
setFeedbackText(data);
84+
},
85+
});
86+
87+
return (<div dangerouslySetInnerHTML={{__html: feedbackText, }}/>); // $ Missing: Alert
88+
}
89+
90+
import { useSubscription } from 'react-relay';
91+
import { useMemo } from 'react';
92+
93+
function func8({GroupLessonsSubscription}) {
94+
const [fragmentRef, setFragmentRef] = useState();
95+
96+
const groupLessonConfig = useMemo(() => ({
97+
subscription: GroupLessonsSubscription,
98+
variables: {},
99+
onNext: (res) => { // $ Missing: Source
100+
setFragmentRef(res);
101+
},
102+
onError: (err) => {
103+
console.error('Error with subscription:', err);
104+
},
105+
onCompleted: () => {
106+
console.log('Subscription completed');
107+
},
108+
}), []);
109+
110+
useSubscription(groupLessonConfig);
111+
112+
return (<div dangerouslySetInnerHTML={{__html: fragmentRef, }}/>); // $ Missing: Alert
113+
}
114+
115+
116+
import { fetchQuery } from 'react-relay'
117+
118+
function func9({query, environment}) {
119+
fetchQuery(environment, query,{id: 4},).subscribe({
120+
start: () => {},
121+
complete: () => {},
122+
error: (error) => {},
123+
next: (data) => { // $ Missing: Source
124+
const outputElement = document.getElementById('output');
125+
if (outputElement) {
126+
outputElement.innerHTML = data.user; // $ Missing: Alert
127+
}
128+
}
129+
});
130+
}
131+
132+
import { readFragment } from "relay-runtime";
133+
134+
function func10({ query, key }) {
135+
const data = readFragment(query, key); // $ Missing: Source
136+
return (<h1 dangerouslySetInnerHTML={{ __html: data }} />); // $ Missing: Alert
137+
}

0 commit comments

Comments
 (0)