Iomatex_OS/android_console/tests/ClientRegistrationTest.java

21 lines
1.8 KiB
Java

package com.iomatex.console;
public final class ClientRegistrationTest {
public static void main(String[] args) {
ClientRegistration c=new ClientRegistration("[meta]\nversion=1\n[registration]\nserver=https://Rest.eva.iomatex.com\ndevice_name=Android-test\npassword=secret\nis_registered=true\n");
if(!c.registered || !c.server.equals("https://Rest.eva.iomatex.com"))throw new AssertionError("canonical store");
c=new ClientRegistration("[General]\nserver=https://old.example\ndevice_name=old\npassword=old\nis_registered=true");
if(c.registered || !c.password.isEmpty())throw new AssertionError("legacy credentials must not resurrect registration");
c=new ClientRegistration("[registration]\nserver=https://new.example\ndevice_name=device\npassword=secret\nis_registered=false");
if(c.registered)throw new AssertionError("registration reset");
c=new ClientRegistration("[registration]\nserver=https://new.example\ndevice_name=device\npassword=\"quoted\\\\value\"\nis_registered=true");
if(!c.password.equals("quoted\\value"))throw new AssertionError("Qt escaped string");
c=new ClientRegistration("[registration]\nserver=\ndevice_name=device\npassword=secret\nis_registered=true");
if(c.registered)throw new AssertionError("missing server is not a default environment");
c=new ClientRegistration("[registration]\nserver=https://new.example\ndevice_name=device\npassword=secret\nis_registered=true\nis_logged=true");
if(!c.logged)throw new AssertionError("confirmed login");
c=new ClientRegistration("[registration]\nserver=https://new.example\ndevice_name=device\npassword=secret\nis_registered=false\nis_logged=true");
if(c.logged)throw new AssertionError("login cannot survive cleared registration");
System.out.println("PASS canonical registration, legacy isolation, reset, quoting, missing server");
}
}