PHP Mock Repository

From F-Droid
Jump to: navigation, search

For testing of repositories that support HTTP Auth, this PHP script may come in handy. It exposes two repositories, one requiring HTTP Auth, the other doesn't. The HTTP Auth repository will accept any username/password combination as it is just for testing.

Script

This uses PHPs build in web server, which is run with the following command:

php -S 192.168.1.100:8888 router.php

Make sure to change the IP address to the address of your server (likely on the local network). Don't bind to localhost or 127.0.0.1 because a separate device such as your Android phone will not be able to connect.

The router.php script is as follows:

<?php
$auth = '/auth';
if (substr($_SERVER['REQUEST_URI'], 0, strlen($auth)) == $auth) {
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
        header('WWW-Authenticate: Basic realm="F-Droid Server"');
        header('HTTP/1.0 401 Unauthorized');
        exit;
    }
}
return false;

Directory Structure

To use it, create the following directory structure:

  • auth
    • fdroid
      • repo
  • regular
    • fdroid
      • repo
  • router.php

And make sure that you have all files required to make an F-Droid server inside the respective repo directories (index.jar, relevant .apk files, etc). One could just be a symlink of the other if you want.

Adding Repositories to Client

Once this is all setup, and your PHP server is running, add repos using the following addresses:

  • 192.168.1.100:8888/auth/fdroid/repo
  • 192.168.1.100:8888/regular/fdroid/repo

Substituting the IP address with the one you used to start the PHP server.