@@ -103,4 +103,39 @@ TEST(nix_isAllowedURI, file_url) {
103103 ASSERT_FALSE (isAllowedURI (" file://" , allowed));
104104}
105105
106+ TEST (nix_isAllowedURI, github_all) {
107+ Strings allowed;
108+ allowed.push_back (" github:" );
109+ ASSERT_TRUE (isAllowedURI (" github:" , allowed));
110+ ASSERT_TRUE (isAllowedURI (" github:foo/bar" , allowed));
111+ ASSERT_TRUE (isAllowedURI (" github:foo/bar/feat-multi-bar" , allowed));
112+ ASSERT_TRUE (isAllowedURI (" github:foo/bar?ref=refs/heads/feat-multi-bar" , allowed));
113+ ASSERT_TRUE (isAllowedURI (" github://foo/bar" , allowed));
114+ ASSERT_FALSE (isAllowedURI (" https://github:443/foo/bar/archive/master.tar.gz" , allowed));
115+ ASSERT_FALSE (isAllowedURI (" file://github:foo/bar/archive/master.tar.gz" , allowed));
116+ ASSERT_FALSE (isAllowedURI (" file:///github:foo/bar/archive/master.tar.gz" , allowed));
117+ ASSERT_FALSE (isAllowedURI (" github" , allowed));
118+ }
119+
120+ TEST (nix_isAllowedURI, github_org) {
121+ Strings allowed;
122+ allowed.push_back (" github:foo" );
123+ ASSERT_FALSE (isAllowedURI (" github:" , allowed));
124+ ASSERT_TRUE (isAllowedURI (" github:foo/bar" , allowed));
125+ ASSERT_TRUE (isAllowedURI (" github:foo/bar/feat-multi-bar" , allowed));
126+ ASSERT_TRUE (isAllowedURI (" github:foo/bar?ref=refs/heads/feat-multi-bar" , allowed));
127+ ASSERT_FALSE (isAllowedURI (" github://foo/bar" , allowed));
128+ ASSERT_FALSE (isAllowedURI (" https://github:443/foo/bar/archive/master.tar.gz" , allowed));
129+ ASSERT_FALSE (isAllowedURI (" file://github:foo/bar/archive/master.tar.gz" , allowed));
130+ ASSERT_FALSE (isAllowedURI (" file:///github:foo/bar/archive/master.tar.gz" , allowed));
131+ }
132+
133+ TEST (nix_isAllowedURI, non_scheme_colon) {
134+ Strings allowed;
135+ allowed.push_back (" https://foo/bar:" );
136+ ASSERT_TRUE (isAllowedURI (" https://foo/bar:" , allowed));
137+ ASSERT_TRUE (isAllowedURI (" https://foo/bar:/baz" , allowed));
138+ ASSERT_FALSE (isAllowedURI (" https://foo/bar:baz" , allowed));
139+ }
140+
106141} // namespace nix
0 commit comments