README.md 3.94 KB
Newer Older
Dom Walden's avatar
Dom Walden committed
1
2
# IPInfo testing

3
4
Scripts to help test IPInfo

5
6
7
`data_from_ip.php`
==================

8
9
10
1. Download https://gitlab.wikimedia.org/DomWalden/ipinfo-testing/-/blob/main/data_from_ip.php
2. In the same directory, download https://github.com/maxmind/GeoIP2-php/releases/download/v2.11.0/geoip2.phar
3. In the same directory, download/move the GeoLite2 databases (the .mmdb files)
Dom Walden's avatar
Typo    
Dom Walden committed
11
4. Run: `php data_from_ip.php <ip address>` (or if you use docker, instead run: `docker-compose exec mediawiki php data_from_ip.php <ip address>`)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

`erd_enterprise.php`
====================

This script will find IP addresses which return different datatypes from MaxMind. This could be used, for example, to test how IPInfo deals with null/empty/zero values.

It will return a CSV. Each row has a different IP address plus all the "expected" values for that IP (based on what MaxMind returns). Each IP has a more-or-less unique combination of return values for each data point we are interested in (e.g. ISP, ASN, Connection Type).

1. Download https://gitlab.wikimedia.org/DomWalden/ipinfo-testing/-/blob/main/erd_enterprise.php
2. In the same directory, download https://github.com/maxmind/GeoIP2-php/releases/download/v2.11.0/geoip2.phar
3. Download and extract the GeoIP2 Enterprise databases (called "GeoIP2 Anonymous IP" and "GeoIP2 Enterprise") and move the .mmdb files into the same directory
4. Download and extract "GeoIP2 Anonymous IP: CSV format" and "GeoIP2 Enterprise: CSV format" and move the .csv files into the same directory
5. Run: `php erd_enterprise.php <input csv> <output csv>` (or if you use docker, instead run: `docker-compose exec mediawiki php erd_enterprise.php <input csv> <output csv>`)
   - Where `<input csv>` is one of either `GeoIP2-Enterprise-Blocks-IPv4.csv` or `GeoIP2-Enterprise-Blocks-IPv6.csv`
   - `<output csv>` is where the results will be written and can be called anything

28
29
30
31
32
33
34
35
36
37
`ipinfo_api_response.py`
========================

This script will take the output .csv file generated by `erd_enterprise.php` and attempt to get output from IPInfo for the IP addresses listed in the .csv file.

It assumes that there is at least one log entry associated with each IP address listed in the .csv file. You could, for example, block each IP address.

It will output another .csv file with two rows for each IP address. One row lists the "expected" result, one the "actual" result.

1. Setup pywikibot using the instructions here https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation
Dom Walden's avatar
Dom Walden committed
38
2. Download and copy https://gitlab.wikimedia.org/DomWalden/ipinfo-testing/-/blob/main/ipinfo_api_response.py into the `scripts/` directory in pywikibot
39
40
41
42
3. Run: `python3 pwb.py ipinfo_api_response -i <input csv> -o <output csv> -n -lang:<lang> -family:<wiki>`
   - Where `<input csv>` is the .csv file generated by `erd_enterprise.php`
   - `<lang>` and `<wiki>` will depend on which environment you are testing IPInfo on

43
44
45
46
47
48
49
`analyse_ipinfo_api_response.R`
===============================

This R script which will help analyse the .csv file generated by `ipinfo_api_response.py`. It will test whether the "expected" and "actual" results match.

It requires the R libraries `tidyr`, `dplyr` and `stringr`.

50
51
52
53
54
55
`edit_from_ip.py`
=================

This script simulates editing a wiki from any IP address you choose.

The wiki you want to edit must have in its LocalSettings.php:
Dom Walden's avatar
Dom Walden committed
56

Dom Walden's avatar
Dom Walden committed
57
	$wgCdnServers = [ '$local_ip_address' ];
58
	$wgUsePrivateIPs = true;
Dom Walden's avatar
Dom Walden committed
59

60
61
62
where `$local_ip_address` is (I believe) your LAN IP address.
 
If you use docker, you might instead want to add:
Dom Walden's avatar
Dom Walden committed
63

64
65
66
67
	$wgCdnServersNoPurge = [ '172.0.0.1/8' ];
	$wgUsePrivateIPs = true;

Then run: `python3 edit_from_ip.py -u $url -i $ip [-t $title]`
Dom Walden's avatar
Dom Walden committed
68
69

Where:
70
71
72
73
74
 - `$url` is the URL of the wiki you want to test, including '/w/api.php'
 - `$ip` is the IP you want to simulate an edit from
 - `$title` is the page you want to edit (this is optional, if you don't pass this parameter it will edit the Main_Page)

For example: `python3 edit_from_ip.py -u http://localhost:8080/w/api.php -i 1.2.3.4`