/** * Create response parameters. */ public OAuthResponseParams(SecurityToken securityToken, HttpRequest originalRequest, BlobCrypter stateCrypter) { this.securityToken = securityToken; this.originalRequest = originalRequest; newClientState = new OAuthClientState(stateCrypter); }
/** * Create response parameters. */ public OAuthResponseParams(SecurityToken securityToken, HttpRequest originalRequest, BlobCrypter stateCrypter) { this.securityToken = securityToken; this.originalRequest = originalRequest; newClientState = new OAuthClientState(stateCrypter); }
/** * Create response parameters. */ public OAuthResponseParams(SecurityToken securityToken, HttpRequest originalRequest, BlobCrypter stateCrypter) { this.securityToken = securityToken; this.originalRequest = originalRequest; newClientState = new OAuthClientState(stateCrypter); }
@Test public void testNullConstructorArg() throws Exception { OAuthClientState state = new OAuthClientState(crypter, null); assertEmpty(state); }
@Test public void testEncryptEmpty() throws Exception { OAuthClientState state = new OAuthClientState(crypter); assertEmpty(state); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEmpty(state); }
@Test public void testEncryptEmpty() throws Exception { OAuthClientState state = new OAuthClientState(crypter); assertEmpty(state); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEmpty(state); }
@Test public void testNullConstructorArg() throws Exception { OAuthClientState state = new OAuthClientState(crypter, null); assertEmpty(state); }
@Test public void testEncryptEmpty() throws Exception { OAuthClientState state = new OAuthClientState(crypter); assertEmpty(state); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEmpty(state); }
@Test public void testNullConstructorArg() throws Exception { OAuthClientState state = new OAuthClientState(crypter, null); assertEmpty(state); }
@Test public void testExpired() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); String encrypted = state.getEncryptedState(); // expiry time + skew. timeSource.incrementSeconds(3600 + 180 + 1); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); }
@Test public void testExpired() throws Exception { OAuthClientState state = new OAuthClientState(crypter); timeSource.incrementSeconds(-1 * (3600 + 180 + 1)); // expiry time + skew. state.setTimeSource(timeSource); state.setRequestToken("reqtoken"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); }
@Test public void testExpired() throws Exception { OAuthClientState state = new OAuthClientState(crypter); timeSource.incrementSeconds(-1 * (3600 + 180 + 1)); // expiry time + skew. state.setTimeSource(timeSource); state.setRequestToken("reqtoken"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); }
/** * OAuth authenticated fetch. */ public HttpResponse fetch(HttpRequest request) { realRequest = request; clientState = new OAuthClientState( fetcherConfig.getStateCrypter(), request.getOAuthArguments().getOrigClientState()); responseParams = new OAuthResponseParams(request.getSecurityToken(), request, fetcherConfig.getStateCrypter()); try { return fetchNoThrow(); } catch (RuntimeException e) { // We log here to record the request/response pairs that created the failure. responseParams.logDetailedWarning(classname,"fetch",MessageKeys.OAUTH_FETCH_UNEXPECTED_ERROR, e); throw e; } }
@Test public void testNullValue() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); state.setRequestToken(null); state.setOwner("owner"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); assertEquals("owner", state.getOwner()); } }
@Test public void testNullValue() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); state.setRequestToken(null); state.setOwner("owner"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); assertEquals("owner", state.getOwner()); } }
@Test public void testNullValue() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setRequestToken("reqtoken"); state.setRequestToken(null); state.setOwner("owner"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertNull(state.getRequestToken()); assertEquals("owner", state.getOwner()); } }
@Test public void testValuesSet() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setAccessToken("atoken"); state.setAccessTokenSecret("atokensecret"); state.setOwner("owner"); state.setRequestToken("reqtoken"); state.setRequestTokenSecret("reqtokensecret"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEquals("atoken", state.getAccessToken()); assertEquals("atokensecret", state.getAccessTokenSecret()); assertEquals("owner", state.getOwner()); assertEquals("reqtoken", state.getRequestToken()); assertEquals("reqtokensecret", state.getRequestTokenSecret()); }
@Test public void testValuesSet() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setAccessToken("atoken"); state.setAccessTokenSecret("atokensecret"); state.setOwner("owner"); state.setRequestToken("reqtoken"); state.setRequestTokenSecret("reqtokensecret"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEquals("atoken", state.getAccessToken()); assertEquals("atokensecret", state.getAccessTokenSecret()); assertEquals("owner", state.getOwner()); assertEquals("reqtoken", state.getRequestToken()); assertEquals("reqtokensecret", state.getRequestTokenSecret()); }
@Test public void testValuesSet() throws Exception { OAuthClientState state = new OAuthClientState(crypter); state.setAccessToken("atoken"); state.setAccessTokenSecret("atokensecret"); state.setOwner("owner"); state.setRequestToken("reqtoken"); state.setRequestTokenSecret("reqtokensecret"); String encrypted = state.getEncryptedState(); state = new OAuthClientState(crypter, encrypted); assertEquals("atoken", state.getAccessToken()); assertEquals("atokensecret", state.getAccessTokenSecret()); assertEquals("owner", state.getOwner()); assertEquals("reqtoken", state.getRequestToken()); assertEquals("reqtokensecret", state.getRequestTokenSecret()); }
@Before public void setUp() throws Exception { backingStore = new BasicOAuthStore(); backingStore.setDefaultKey(new BasicOAuthStoreConsumerKeyAndSecret("key", "secret", KeyType.RSA_PRIVATE, "keyname", null)); backingStore.setDefaultCallbackUrl(DEFAULT_CALLBACK); store = new GadgetOAuthTokenStore(backingStore, new FakeGadgetSpecFactory()); socialToken = new FakeGadgetToken(); socialToken.setOwnerId("owner"); socialToken.setViewerId("viewer"); socialToken.setAppUrl(GADGET_URL); privateToken = new FakeGadgetToken(); privateToken.setOwnerId("owner"); privateToken.setViewerId("owner"); privateToken.setAppUrl(GADGET_URL); stateCrypter = new BasicBlobCrypter("abcdefghijklmnop".getBytes()); clientState = new OAuthClientState(stateCrypter); responseParams = new OAuthResponseParams(socialToken, null, stateCrypter); fetcherConfig = new OAuthFetcherConfig(stateCrypter, store, new FakeTimeSource(), null, false); }