@@ -88,6 +88,42 @@ test("should detect shady link when an URL is bit.ly", () => {
8888 assert . strictEqual ( warning . value , "http://bit.ly/foo" ) ;
8989} ) ;
9090
91+ test ( "should detect shady link when an URL is ipinfo.io when protocol is http" , ( ) => {
92+ const str = "const foo = 'http://ipinfo.io/json'" ;
93+ const ast = parseScript ( str ) ;
94+ const sastAnalysis = getSastAnalysis ( str , isLiteral ) . execute ( ast . body ) ;
95+ assert . strictEqual ( sastAnalysis . warnings ( ) . length , 1 ) ;
96+ const warning = sastAnalysis . getWarning ( "shady-link" ) ;
97+ assert . strictEqual ( warning . value , "http://ipinfo.io/json" ) ;
98+ } ) ;
99+
100+ test ( "should detect shady link when an URL is ipinfo.io when protocol is https" , ( ) => {
101+ const str = "const foo = 'https://ipinfo.io/json'" ;
102+ const ast = parseScript ( str ) ;
103+ const sastAnalysis = getSastAnalysis ( str , isLiteral ) . execute ( ast . body ) ;
104+ assert . strictEqual ( sastAnalysis . warnings ( ) . length , 1 ) ;
105+ const warning = sastAnalysis . getWarning ( "shady-link" ) ;
106+ assert . strictEqual ( warning . value , "https://ipinfo.io/json" ) ;
107+ } ) ;
108+
109+ test ( "should detect shady link when an URL is httpbin.org when protocol is http" , ( ) => {
110+ const str = "const foo = 'http://httpbin.org/ip'" ;
111+ const ast = parseScript ( str ) ;
112+ const sastAnalysis = getSastAnalysis ( str , isLiteral ) . execute ( ast . body ) ;
113+ assert . strictEqual ( sastAnalysis . warnings ( ) . length , 1 ) ;
114+ const warning = sastAnalysis . getWarning ( "shady-link" ) ;
115+ assert . strictEqual ( warning . value , "http://httpbin.org/ip" ) ;
116+ } ) ;
117+
118+ test ( "should detect shady link when an URL is httpbin.org when protocol is https" , ( ) => {
119+ const str = "const foo = 'https://httpbin.org/ip'" ;
120+ const ast = parseScript ( str ) ;
121+ const sastAnalysis = getSastAnalysis ( str , isLiteral ) . execute ( ast . body ) ;
122+ assert . strictEqual ( sastAnalysis . warnings ( ) . length , 1 ) ;
123+ const warning = sastAnalysis . getWarning ( "shady-link" ) ;
124+ assert . strictEqual ( warning . value , "https://httpbin.org/ip" ) ;
125+ } ) ;
126+
91127test ( "should detect shady link when an URL has a suspicious domain" , ( ) => {
92128 const str = "const foo = 'http://foobar.link'" ;
93129 const ast = parseScript ( str ) ;
0 commit comments