@@ -1110,16 +1110,19 @@ def test_create_own_redirect_for_old_apache_version(self):
1110
1110
self .config ._enable_redirect (self .vh_truth [1 ], "" )
1111
1111
self .assertEqual (len (self .config .vhosts ), 9 )
1112
1112
1113
- def test_sift_line (self ):
1113
+ def test_sift_rewrite_rule (self ):
1114
1114
# pylint: disable=protected-access
1115
1115
small_quoted_target = "RewriteRule ^ \" http://\" "
1116
- self .assertFalse (self .config ._sift_line (small_quoted_target ))
1116
+ self .assertFalse (self .config ._sift_rewrite_rule (small_quoted_target ))
1117
1117
1118
1118
https_target = "RewriteRule ^ https://satoshi"
1119
- self .assertTrue (self .config ._sift_line (https_target ))
1119
+ self .assertTrue (self .config ._sift_rewrite_rule (https_target ))
1120
1120
1121
1121
normal_target = "RewriteRule ^/(.*) http://www.a.com:1234/$1 [L,R]"
1122
- self .assertFalse (self .config ._sift_line (normal_target ))
1122
+ self .assertFalse (self .config ._sift_rewrite_rule (normal_target ))
1123
+
1124
+ not_rewriterule = "NotRewriteRule ^ ..."
1125
+ self .assertFalse (self .config ._sift_rewrite_rule (not_rewriterule ))
1123
1126
1124
1127
@mock .patch ("certbot_apache.configurator.zope.component.getUtility" )
1125
1128
def test_make_vhost_ssl_with_existing_rewrite_rule (self , mock_get_utility ):
@@ -1148,7 +1151,61 @@ def test_make_vhost_ssl_with_existing_rewrite_rule(self, mock_get_utility):
1148
1151
"[L,QSA,R=permanent]" )
1149
1152
self .assertTrue (commented_rewrite_rule in conf_text )
1150
1153
mock_get_utility ().add_message .assert_called_once_with (mock .ANY ,
1154
+
1151
1155
mock .ANY )
1156
+ @mock .patch ("certbot_apache.configurator.zope.component.getUtility" )
1157
+ def test_make_vhost_ssl_with_existing_rewrite_conds (self , mock_get_utility ):
1158
+ self .config .parser .modules .add ("rewrite_module" )
1159
+
1160
+ http_vhost = self .vh_truth [0 ]
1161
+
1162
+ self .config .parser .add_dir (
1163
+ http_vhost .path , "RewriteEngine" , "on" )
1164
+
1165
+ # Add a chunk that should not be commented out.
1166
+ self .config .parser .add_dir (http_vhost .path ,
1167
+ "RewriteCond" , ["%{DOCUMENT_ROOT}/%{REQUEST_FILENAME}" , "!-f" ])
1168
+ self .config .parser .add_dir (
1169
+ http_vhost .path , "RewriteRule" ,
1170
+ ["^(.*)$" , "b://u%{REQUEST_URI}" , "[P,QSA,L]" ])
1171
+
1172
+ # Add a chunk that should be commented out.
1173
+ self .config .parser .add_dir (http_vhost .path ,
1174
+ "RewriteCond" , ["%{HTTPS}" , "!=on" ])
1175
+ self .config .parser .add_dir (http_vhost .path ,
1176
+ "RewriteCond" , ["%{HTTPS}" , "!^$" ])
1177
+ self .config .parser .add_dir (
1178
+ http_vhost .path , "RewriteRule" ,
1179
+ ["^" ,
1180
+ "https://%{SERVER_NAME}%{REQUEST_URI}" ,
1181
+ "[L,QSA,R=permanent]" ])
1182
+
1183
+ self .config .save ()
1184
+
1185
+ ssl_vhost = self .config .make_vhost_ssl (self .vh_truth [0 ])
1186
+
1187
+ conf_line_set = set (open (ssl_vhost .filep ).read ().splitlines ())
1188
+
1189
+ not_commented_cond1 = ("RewriteCond "
1190
+ "%{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f" )
1191
+ not_commented_rewrite_rule = ("RewriteRule "
1192
+ "^(.*)$ b://u%{REQUEST_URI} [P,QSA,L]" )
1193
+
1194
+ commented_cond1 = "# RewriteCond %{HTTPS} !=on"
1195
+ commented_cond2 = "# RewriteCond %{HTTPS} !^$"
1196
+ commented_rewrite_rule = ("# RewriteRule ^ "
1197
+ "https://%{SERVER_NAME}%{REQUEST_URI} "
1198
+ "[L,QSA,R=permanent]" )
1199
+
1200
+ self .assertTrue (not_commented_cond1 in conf_line_set )
1201
+ self .assertTrue (not_commented_rewrite_rule in conf_line_set )
1202
+
1203
+ self .assertTrue (commented_cond1 in conf_line_set )
1204
+ self .assertTrue (commented_cond2 in conf_line_set )
1205
+ self .assertTrue (commented_rewrite_rule in conf_line_set )
1206
+ mock_get_utility ().add_message .assert_called_once_with (mock .ANY ,
1207
+ mock .ANY )
1208
+
1152
1209
1153
1210
def get_achalls (self ):
1154
1211
"""Return testing achallenges."""
0 commit comments