reTHINK-project / dev-registry-global

Global Registry
Apache License 2.0
4 stars 0 forks source link

GlobalRegistryTest #8

Closed sgoendoer closed 7 years ago

sgoendoer commented 8 years ago

This is a small test class that tests the GReg interfaces

It basically just creates a dataset and keypair, puts it in a signed JWT and posts it to the GReg. Then, it pulls the same dataset from another GReg node.

public class GlobalRegistryTest { public static void main(String[] args) { try { System.out.print("Creating keypair...");

        KeyPair keypair = KeyPairManager.createKeyPair();

        String publicKey = KeyPairManager.encodePublicKey(keypair.getPublic());
        String privateKey = KeyPairManager.encodePrivateKey(keypair.getPrivate());

        System.out.print("OK\nCreating mock dataset...");

        String datasetstring = "{\"UserIDs\": [\"reTHINK://somedomain.com/123\", \"reTHINK://facebook.com/fluffy123\"],\"salt\": \"eadf5f8e396724da\",\"active\": 1,\"revoked\": 0}";
        JSONObject dataset = new JSONObject(datasetstring);

        dataset.put("publicKey", publicKey);

        dataset.put("updated", XSDDateTime.exportXSDDateTime(new Date()));

        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, 28);
        dataset.put("timeout", XSDDateTime.exportXSDDateTime(c.getTime()));

        System.out.print("OK\nCreating GUID...");

        String guid = GUID.createGUID(publicKey, dataset.getString("salt"));

        dataset.put("guid", guid);

        System.out.print("OK\n[ GUID : " + guid + " ]\n[ dataset : " + dataset.toString() + " ]\nCreating JWT...");

        String jwt = Jwts.builder().claim("data", dataset.toString()).signWith(SignatureAlgorithm.RS512, keypair.getPrivate()).compact();

        System.out.print("OK\n[ JWT : " + jwt + " ]\nPosting to Global Registry [130.149.22.133:5002]...");

        GlobalRegistryAPI.putData("130.149.22.133:5002", guid, jwt);

        System.out.print("OK\nRequesting data from Global Registry [130.149.22.135:5002]...");

        String jwt2 = GlobalRegistryAPI.getData("130.149.22.135:5002", guid);

        System.out.print("OK\n[ JWT : " + jwt2 + " ]\n\n");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

}

sgoendoer commented 8 years ago

A thorough test has been implemented within the registry package. See Wiki for more information.