Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.sync; |
michael@0 | 5 | |
michael@0 | 6 | import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; |
michael@0 | 7 | import org.mozilla.gecko.sync.SyncConstants; |
michael@0 | 8 | import org.mozilla.gecko.sync.Utils; |
michael@0 | 9 | import org.mozilla.gecko.sync.setup.Constants; |
michael@0 | 10 | import org.mozilla.gecko.sync.setup.SyncAccounts; |
michael@0 | 11 | import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters; |
michael@0 | 12 | import org.mozilla.gecko.sync.setup.SyncAuthenticatorService; |
michael@0 | 13 | |
michael@0 | 14 | import android.accounts.Account; |
michael@0 | 15 | import android.accounts.AccountManager; |
michael@0 | 16 | import android.content.Context; |
michael@0 | 17 | import android.os.Bundle; |
michael@0 | 18 | |
michael@0 | 19 | public class TestSyncAuthenticatorService extends AndroidSyncTestCase { |
michael@0 | 20 | private static final String TEST_USERNAME = "testAccount@mozilla.com"; |
michael@0 | 21 | private static final String TEST_SYNCKEY = "testSyncKey"; |
michael@0 | 22 | private static final String TEST_PASSWORD = "testPassword"; |
michael@0 | 23 | private static final String TEST_SERVERURL = "test.server.url/"; |
michael@0 | 24 | |
michael@0 | 25 | private Account account; |
michael@0 | 26 | private Context context; |
michael@0 | 27 | private AccountManager accountManager; |
michael@0 | 28 | private SyncAccountParameters syncAccount; |
michael@0 | 29 | |
michael@0 | 30 | public void setUp() { |
michael@0 | 31 | account = null; |
michael@0 | 32 | context = getApplicationContext(); |
michael@0 | 33 | accountManager = AccountManager.get(context); |
michael@0 | 34 | syncAccount = new SyncAccountParameters(context, accountManager, |
michael@0 | 35 | TEST_USERNAME, TEST_SYNCKEY, TEST_PASSWORD, TEST_SERVERURL); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | public void tearDown() { |
michael@0 | 39 | if (account == null) { |
michael@0 | 40 | return; |
michael@0 | 41 | } |
michael@0 | 42 | TestSyncAccounts.deleteAccount(this, accountManager, account); |
michael@0 | 43 | account = null; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | public void testGetPlainAuthToken() throws Exception { |
michael@0 | 47 | account = SyncAccounts.createSyncAccount(syncAccount, false); |
michael@0 | 48 | assertNotNull(account); |
michael@0 | 49 | |
michael@0 | 50 | final Bundle bundle = SyncAuthenticatorService.getPlainAuthToken(context, account); |
michael@0 | 51 | |
michael@0 | 52 | assertEquals(TEST_USERNAME, bundle.getString(AccountManager.KEY_ACCOUNT_NAME)); |
michael@0 | 53 | assertEquals(SyncConstants.ACCOUNTTYPE_SYNC, bundle.getString(AccountManager.KEY_ACCOUNT_TYPE)); |
michael@0 | 54 | assertEquals(Utils.usernameFromAccount(TEST_USERNAME), bundle.getString(Constants.OPTION_USERNAME)); |
michael@0 | 55 | assertEquals(TEST_PASSWORD, bundle.getString(AccountManager.KEY_AUTHTOKEN)); |
michael@0 | 56 | assertEquals(TEST_SYNCKEY, bundle.getString(Constants.OPTION_SYNCKEY)); |
michael@0 | 57 | assertEquals(TEST_SERVERURL, bundle.getString(Constants.OPTION_SERVER)); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | public void testGetBadTokenType() throws Exception { |
michael@0 | 61 | account = SyncAccounts.createSyncAccount(syncAccount, false); |
michael@0 | 62 | assertNotNull(account); |
michael@0 | 63 | |
michael@0 | 64 | assertNull(accountManager.blockingGetAuthToken(account, "BAD_TOKEN_TYPE", false)); |
michael@0 | 65 | } |
michael@0 | 66 | } |