Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 277903002: Sanitize referrers for programmatic downloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CONTENT_EXPORT Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 2917 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 // The release callback runs before the delete is scheduled, so pump the 2928 // The release callback runs before the delete is scheduled, so pump the
2929 // message loop for the delete itself. (This relies on the delete happening on 2929 // message loop for the delete itself. (This relies on the delete happening on
2930 // the FILE thread which is mapped to main thread in this test.) 2930 // the FILE thread which is mapped to main thread in this test.)
2931 base::RunLoop().RunUntilIdle(); 2931 base::RunLoop().RunUntilIdle();
2932 2932
2933 EXPECT_FALSE(base::PathExists(response_head.download_file_path)); 2933 EXPECT_FALSE(base::PathExists(response_head.download_file_path));
2934 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( 2934 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
2935 filter_->child_id(), response_head.download_file_path)); 2935 filter_->child_id(), response_head.download_file_path));
2936 } 2936 }
2937 2937
2938 namespace {
2939
2940 void MatchSanitizedReferrer(
2941 const std::string& original_referrer_url,
2942 blink::WebReferrerPolicy referrer_policy,
2943 const std::string& request_url,
2944 const std::string& expected_sanitized_referrer_url) {
2945 Referrer sanitized_referrer = SanitizeReferrerForRequest(
2946 GURL(request_url),
2947 Referrer(GURL(original_referrer_url), referrer_policy));
2948 EXPECT_EQ(GURL(expected_sanitized_referrer_url), sanitized_referrer.url);
2949 EXPECT_EQ(referrer_policy, sanitized_referrer.policy);
2950 }
2951
2952 }
2953
2954 TEST(SanitizeReferrerForRequestTest, HttpReferrerHttpRequest) {
2955 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2956 blink::WebReferrerPolicyAlways,
2957 "http://bar.example.com",
2958 "http://foo.example.com/path");
2959 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2960 blink::WebReferrerPolicyDefault,
2961 "http://bar.example.com",
2962 "http://foo.example.com/path");
2963 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2964 blink::WebReferrerPolicyOrigin,
2965 "http://bar.example.com",
2966 "http://foo.example.com");
2967 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2968 blink::WebReferrerPolicyNever,
2969 "http://bar.example.com",
2970 "");
2971 }
2972
2973 TEST(SanitizeReferrerForRequestTest, HttpReferrerHttpsRequest) {
2974 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2975 blink::WebReferrerPolicyAlways,
2976 "https://bar.example.com",
2977 "http://foo.example.com/path");
2978 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2979 blink::WebReferrerPolicyDefault,
2980 "https://bar.example.com",
2981 "http://foo.example.com/path");
2982 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2983 blink::WebReferrerPolicyOrigin,
2984 "https://bar.example.com",
2985 "http://foo.example.com");
2986 MatchSanitizedReferrer("http://user:pass@foo.example.com/path#frag",
2987 blink::WebReferrerPolicyNever,
2988 "https://bar.example.com",
2989 "");
2990 }
2991
2992 TEST(SanitizeReferrerForRequestTest, HttpsReferrerHttpRequest) {
2993 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
2994 blink::WebReferrerPolicyAlways,
2995 "http://bar.example.com",
2996 "https://foo.example.com/path");
2997 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
2998 blink::WebReferrerPolicyDefault,
2999 "http://bar.example.com",
3000 "");
3001 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
3002 blink::WebReferrerPolicyOrigin,
3003 "http://bar.example.com",
3004 "https://foo.example.com");
3005 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
3006 blink::WebReferrerPolicyNever,
3007 "http://bar.example.com",
3008 "");
3009 }
3010
3011 TEST(SanitizeReferrerForRequestTest, HttpsReferrerHttpsRequest) {
3012 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
3013 blink::WebReferrerPolicyAlways,
3014 "https://bar.example.com",
3015 "https://foo.example.com/path");
3016 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
3017 blink::WebReferrerPolicyDefault,
3018 "https://bar.example.com",
3019 "https://foo.example.com/path");
3020 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
3021 blink::WebReferrerPolicyOrigin,
3022 "https://bar.example.com",
3023 "https://foo.example.com");
3024 MatchSanitizedReferrer("https://user:pass@foo.example.com/path#frag",
3025 blink::WebReferrerPolicyNever,
3026 "https://bar.example.com",
3027 "");
3028 }
3029
2938 } // namespace content 3030 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698