| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # exit when any command fails | 
					
						
							|  |  |  | set -e | 
					
						
							| 
									
										
										
										
											2023-09-08 12:14:47 +00:00
										 |  |  | # enable debug | 
					
						
							|  |  |  | set -x | 
					
						
							| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Test proxy list handling, starting two squids on different ports | 
					
						
							|  |  |  | # Each squid adds a different header to the response, which is the main thing we test for. | 
					
						
							|  |  |  | docker run --network changedet-network -d --name squid-one --hostname squid-one --rm -v `pwd`/tests/proxy_list/squid.conf:/etc/squid/conf.d/debian.conf ubuntu/squid:4.13-21.10_edge | 
					
						
							|  |  |  | docker run --network changedet-network -d --name squid-two --hostname squid-two --rm -v `pwd`/tests/proxy_list/squid.conf:/etc/squid/conf.d/debian.conf ubuntu/squid:4.13-21.10_edge | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  | # Used for configuring a custom proxy URL via the UI - with username+password auth | 
					
						
							| 
									
										
										
										
											2022-12-19 20:48:01 +00:00
										 |  |  | docker run --network changedet-network -d \
 | 
					
						
							|  |  |  |   --name squid-custom \
 | 
					
						
							| 
									
										
										
										
											2022-12-26 13:17:40 +00:00
										 |  |  |   --hostname squid-custom \
 | 
					
						
							| 
									
										
										
										
											2022-12-19 20:48:01 +00:00
										 |  |  |   --rm \
 | 
					
						
							|  |  |  |   -v `pwd`/tests/proxy_list/squid-auth.conf:/etc/squid/conf.d/debian.conf \
 | 
					
						
							|  |  |  |   -v `pwd`/tests/proxy_list/squid-passwords.txt:/etc/squid3/passwords \
 | 
					
						
							|  |  |  |   ubuntu/squid:4.13-21.10_edge | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## 2nd test actually choose the preferred proxy from proxies.json | 
					
						
							|  |  |  | docker run --network changedet-network \
 | 
					
						
							|  |  |  |   -v `pwd`/tests/proxy_list/proxies.json-example:/app/changedetectionio/test-datastore/proxies.json \
 | 
					
						
							|  |  |  |   test-changedetectionio \
 | 
					
						
							|  |  |  |   bash -c 'cd changedetectionio && pytest tests/proxy_list/test_multiple_proxy.py' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  | set +e | 
					
						
							|  |  |  | echo "- Looking for chosen.changedetection.io request in squid-one - it should NOT be here" | 
					
						
							| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  | docker logs squid-one 2>/dev/null|grep chosen.changedetection.io | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  | if [ $? -ne 1 ] | 
					
						
							| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  | then | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  |   echo "Saw a request to chosen.changedetection.io in the squid logs (while checking preferred proxy - squid one) WHEN I SHOULD NOT" | 
					
						
							| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  | set -e | 
					
						
							|  |  |  | echo "- Looking for chosen.changedetection.io request in squid-two" | 
					
						
							| 
									
										
										
										
											2022-12-19 13:41:34 +00:00
										 |  |  | # And one in the 'second' squid (user selects this as preferred) | 
					
						
							|  |  |  | docker logs squid-two 2>/dev/null|grep chosen.changedetection.io | 
					
						
							|  |  |  | if [ $? -ne 0 ] | 
					
						
							|  |  |  | then | 
					
						
							|  |  |  |   echo "Did not see a request to chosen.changedetection.io in the squid logs (while checking preferred proxy - squid two)" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2022-12-19 20:48:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Test the UI configurable proxies | 
					
						
							|  |  |  | docker run --network changedet-network \
 | 
					
						
							|  |  |  |   test-changedetectionio \
 | 
					
						
							|  |  |  |   bash -c 'cd changedetectionio && pytest tests/proxy_list/test_select_custom_proxy.py' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Should see a request for one.changedetection.io in there | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  | echo "- Looking for .changedetection.io request in squid-custom" | 
					
						
							| 
									
										
										
										
											2022-12-19 20:48:01 +00:00
										 |  |  | docker logs squid-custom 2>/dev/null|grep "TCP_TUNNEL.200.*changedetection.io" | 
					
						
							|  |  |  | if [ $? -ne 0 ] | 
					
						
							|  |  |  | then | 
					
						
							|  |  |  |   echo "Did not see a valid request to changedetection.io in the squid logs (while checking preferred proxy - squid two)" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2022-12-26 13:17:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-08 12:14:47 +00:00
										 |  |  | # Test "no-proxy" option | 
					
						
							|  |  |  | docker run --network changedet-network \
 | 
					
						
							|  |  |  |   test-changedetectionio \
 | 
					
						
							|  |  |  |   bash -c 'cd changedetectionio && pytest tests/proxy_list/test_noproxy.py' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # We need to handle grep returning 1 | 
					
						
							|  |  |  | set +e | 
					
						
							|  |  |  | # Check request was never seen in any container | 
					
						
							|  |  |  | for c in $(echo "squid-one squid-two squid-custom"); do | 
					
						
							| 
									
										
										
										
											2024-02-10 23:09:12 +00:00
										 |  |  |   echo ....Checking $c | 
					
						
							| 
									
										
										
										
											2023-09-08 12:14:47 +00:00
										 |  |  |   docker logs $c &> $c.txt | 
					
						
							|  |  |  |   grep noproxy $c.txt | 
					
						
							|  |  |  |   if [ $? -ne 1 ] | 
					
						
							|  |  |  |   then | 
					
						
							|  |  |  |     echo "Saw request for noproxy in $c container" | 
					
						
							|  |  |  |     cat $c.txt | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-26 13:17:40 +00:00
										 |  |  | docker kill squid-one squid-two squid-custom |