use of com.vodafone360.people.datatypes.PublicKeyDetails in project 360-Engine-for-Android by 360.
the class NowPlusDBHelperLoginTest method testModifyCredentialsAndKey.
/*
* Modify credentials and public key then fetch modified credentials and validate it
*/
@MediumTest
public void testModifyCredentialsAndKey() {
Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContactsDetails *****");
Log.i(LOG_TAG, "Test contact functionality (add delete contacts details)");
Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
assertTrue(initialise());
Log.i(LOG_TAG, "Test 1b: Remove user data");
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
assertEquals(ServiceStatus.SUCCESS, status);
RegistrationDetails registrationDetails = new RegistrationDetails();
registrationDetails.mUsername = TestModule.generateRandomString();
registrationDetails.mPassword = TestModule.generateRandomString();
registrationDetails.mMsisdn = TestModule.generateRandomString();
LoginDetails loginDetails = new LoginDetails();
loginDetails.mUsername = registrationDetails.mUsername;
loginDetails.mPassword = registrationDetails.mPassword;
loginDetails.mAutoConnect = TestModule.generateRandomBoolean();
loginDetails.mRememberMe = TestModule.generateRandomBoolean();
loginDetails.mMobileNo = registrationDetails.mMsisdn;
loginDetails.mSubscriberId = TestModule.generateRandomString();
PublicKeyDetails pubKeyDetails = new PublicKeyDetails();
RSAEncryptionUtils.copyDefaultPublicKey(pubKeyDetails);
pubKeyDetails.mKeyBase64 = TestModule.generateRandomString();
LoginDetails fetchedLogin = new LoginDetails();
PublicKeyDetails fetchedPubKey = new PublicKeyDetails();
status = mDatabaseHelper.fetchLogonCredentialsAndPublicKey(fetchedLogin, fetchedPubKey);
assertEquals(ServiceStatus.SUCCESS, status);
assertNull(fetchedLogin.mUsername);
assertNull(fetchedLogin.mPassword);
assertNull(fetchedPubKey.mKeyBase64);
assertNull(fetchedPubKey.mExponential);
assertNull(fetchedPubKey.mModulus);
status = mDatabaseHelper.modifyCredentialsAndPublicKey(loginDetails, pubKeyDetails);
assertEquals(ServiceStatus.SUCCESS, status);
status = mDatabaseHelper.fetchLogonCredentialsAndPublicKey(fetchedLogin, fetchedPubKey);
assertEquals(ServiceStatus.SUCCESS, status);
assertEquals(loginDetails.mUsername, fetchedLogin.mUsername);
if (loginDetails.mRememberMe) {
assertEquals(loginDetails.mPassword, fetchedLogin.mPassword);
}
assertEquals(loginDetails.mAutoConnect, fetchedLogin.mAutoConnect);
assertEquals(loginDetails.mRememberMe, fetchedLogin.mRememberMe);
assertEquals(loginDetails.mMobileNo, fetchedLogin.mMobileNo);
assertEquals(loginDetails.mSubscriberId, fetchedLogin.mSubscriberId);
assertEquals(pubKeyDetails.mExponential.length, fetchedPubKey.mExponential.length);
for (int i = 0; i < pubKeyDetails.mExponential.length; i++) {
assertEquals(pubKeyDetails.mExponential[i], fetchedPubKey.mExponential[i]);
}
assertEquals(pubKeyDetails.mModulus.length, fetchedPubKey.mModulus.length);
for (int i = 0; i < fetchedPubKey.mModulus.length; i++) {
assertEquals(pubKeyDetails.mModulus[i], fetchedPubKey.mModulus[i]);
}
assertEquals(pubKeyDetails.mKeyBase64, fetchedPubKey.mKeyBase64);
shutdown();
Log.i(LOG_TAG, "*************************************");
Log.i(LOG_TAG, "testModifyFetchCredentials has completed successfully");
Log.i(LOG_TAG, "**************************************");
}
use of com.vodafone360.people.datatypes.PublicKeyDetails in project 360-Engine-for-Android by 360.
the class NowPlusStateTableTest method testModifyCredentialsAndKey.
/*
* Modify credentials and public key then fetch modified credentials and
* validate it
*/
@MediumTest
public void testModifyCredentialsAndKey() {
final String fnName = "testModifyCredentialsAndKey";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "modfiy and fetchmodified credentials");
SQLiteDatabase writableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
LoginDetails loginDetails = new LoginDetails();
RegistrationDetails registrationDetails = new RegistrationDetails();
registrationDetails.mUsername = TestModule.generateRandomString();
registrationDetails.mPassword = TestModule.generateRandomString();
registrationDetails.mMsisdn = TestModule.generateRandomString();
loginDetails.mUsername = registrationDetails.mUsername;
loginDetails.mPassword = registrationDetails.mPassword;
loginDetails.mAutoConnect = true;
loginDetails.mRememberMe = true;
loginDetails.mMobileNo = registrationDetails.mMsisdn;
loginDetails.mSubscriberId = TestModule.generateRandomString();
PublicKeyDetails pubKeyDetails = new PublicKeyDetails();
RSAEncryptionUtils.copyDefaultPublicKey(pubKeyDetails);
// try to modify credentials before creating a table causes uncaught
// exception
ServiceStatus status = StateTable.modifyCredentialsAndPublicKey(loginDetails, pubKeyDetails, writableDb);
assertEquals(ServiceStatus.ERROR_DATABASE_CORRUPT, status);
createTable();
// positive test modify credentials after table was created
status = StateTable.modifyCredentialsAndPublicKey(loginDetails, pubKeyDetails, writableDb);
assertEquals(ServiceStatus.SUCCESS, status);
PublicKeyDetails fetchedPubKey = new PublicKeyDetails();
LoginDetails fetchedLoginDetails = new LoginDetails();
status = StateTable.fetchLogonCredentialsAndPublicKey(fetchedLoginDetails, fetchedPubKey, readableDb);
assertEquals(ServiceStatus.SUCCESS, status);
assertEquals(loginDetails.mUsername, fetchedLoginDetails.mUsername);
assertEquals(loginDetails.mPassword, fetchedLoginDetails.mPassword);
assertEquals(loginDetails.mAutoConnect, fetchedLoginDetails.mAutoConnect);
assertEquals(loginDetails.mRememberMe, fetchedLoginDetails.mRememberMe);
assertEquals(loginDetails.mMobileNo, fetchedLoginDetails.mMobileNo);
assertEquals(loginDetails.mSubscriberId, fetchedLoginDetails.mSubscriberId);
assertEquals(pubKeyDetails.mExponential.length, fetchedPubKey.mExponential.length);
for (int i = 0; i < pubKeyDetails.mExponential.length; i++) {
assertEquals(pubKeyDetails.mExponential[i], fetchedPubKey.mExponential[i]);
}
assertEquals(pubKeyDetails.mModulus.length, fetchedPubKey.mModulus.length);
for (int i = 0; i < fetchedPubKey.mModulus.length; i++) {
assertEquals(pubKeyDetails.mModulus[i], fetchedPubKey.mModulus[i]);
}
loginDetails.mRememberMe = false;
pubKeyDetails.mKeyBase64 = TestModule.generateRandomString();
status = StateTable.modifyCredentialsAndPublicKey(loginDetails, pubKeyDetails, writableDb);
assertEquals(ServiceStatus.SUCCESS, status);
LoginDetails modifedLoginDetails = new LoginDetails();
PublicKeyDetails modifiedPubKey = new PublicKeyDetails();
status = StateTable.fetchLogonCredentialsAndPublicKey(modifedLoginDetails, modifiedPubKey, readableDb);
assertEquals(ServiceStatus.SUCCESS, status);
assertEquals(loginDetails.mUsername, modifedLoginDetails.mUsername);
// mRemberme was set to false
assertNull(modifedLoginDetails.mPassword);
// so password should be null
assertEquals(loginDetails.mAutoConnect, modifedLoginDetails.mAutoConnect);
assertEquals(loginDetails.mRememberMe, modifedLoginDetails.mRememberMe);
assertEquals(loginDetails.mMobileNo, modifedLoginDetails.mMobileNo);
assertEquals(loginDetails.mSubscriberId, modifedLoginDetails.mSubscriberId);
assertEquals(pubKeyDetails.mExponential.length, modifiedPubKey.mExponential.length);
for (int i = 0; i < pubKeyDetails.mExponential.length; i++) {
assertEquals(pubKeyDetails.mExponential[i], fetchedPubKey.mExponential[i]);
}
assertEquals(pubKeyDetails.mModulus.length, modifiedPubKey.mModulus.length);
for (int i = 0; i < fetchedPubKey.mModulus.length; i++) {
assertEquals(pubKeyDetails.mModulus[i], fetchedPubKey.mModulus[i]);
}
assertEquals(pubKeyDetails.mKeyBase64, modifiedPubKey.mKeyBase64);
Log.i(LOG_TAG, "*************************************");
Log.i(LOG_TAG, "testModifyCredentialsAndKey has completed successfully");
Log.i(LOG_TAG, "**************************************");
}
use of com.vodafone360.people.datatypes.PublicKeyDetails in project 360-Engine-for-Android by 360.
the class NowPlusDatatypesTests method testPublicKeyDetails.
public void testPublicKeyDetails() {
byte[] modulo = new byte[] { 0, 0 };
byte[] exponential = new byte[] { 0, 1 };
byte[] key = new byte[] { 1, 1 };
String keyBase64 = "64";
PublicKeyDetails input = new PublicKeyDetails();
input.mModulus = modulo;
input.mExponential = exponential;
input.mKeyX509 = key;
input.mKeyBase64 = keyBase64;
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put("modulo", modulo);
hash.put("exponential", exponential);
hash.put("key", key);
hash.put("keybase64", keyBase64);
PublicKeyDetails output = PublicKeyDetails.createFromHashtable(hash);
assertEquals(input.describeContents(), output.describeContents());
assertEquals(input.getType(), output.getType());
assertEquals(input.toString(), output.toString());
assertEquals(input.mModulus, output.mModulus);
assertEquals(input.mExponential, output.mExponential);
assertEquals(input.mKeyX509, output.mKeyX509);
assertEquals(input.mKeyBase64, output.mKeyBase64);
}
use of com.vodafone360.people.datatypes.PublicKeyDetails in project 360-Engine-for-Android by 360.
the class LoginEngine method handleNewPublicKeyResponse.
/**
* Called when a response to the server fetch public key request is
* received. Validates the response and stores the new public key details.
*
* @param mDataTypes Response data from server.
*/
private void handleNewPublicKeyResponse(List<BaseDataType> mDataTypes) {
LogUtils.logD("LoginEngine.handleNewPublicKeyResponse()");
ServiceStatus errorStatus = getResponseStatus(BaseDataType.PUBLIC_KEY_DETAILS_DATA_TYPE, mDataTypes);
if (errorStatus == ServiceStatus.SUCCESS) {
LogUtils.logD("LoginEngine.handleNewPublicKeyResponse() - Succesfully retrieved");
// AA
// 1. save to DB; save the flag that we aren't using default and
// have to use one from DB
// 2. start registration again
mPublicKey = (PublicKeyDetails) mDataTypes.get(0);
// done in startRegistrationProcessCrypted already
// mDb.modifyCredentialsAndPublicKey(mLoginDetails, mPublicKey);
startRegistrationProcessCrypted(mRegistrationDetails);
} else {
completeUiRequest(errorStatus, null);
}
}
Aggregations