Search in sources :

Example 1 with PlainTextPersistenceProcessor

use of org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2UtilTest method testAuthenticateClientCacheHit.

@Test
public void testAuthenticateClientCacheHit() throws Exception {
    OAuthAppDO appDO = new OAuthAppDO();
    appDO.setOauthConsumerKey(clientId);
    appDO.setOauthConsumerSecret(clientSecret);
    AppInfoCache appInfoCache = mock(AppInfoCache.class);
    when(appInfoCache.getValueFromCache(clientId)).thenReturn(appDO);
    mockStatic(AppInfoCache.class);
    when(AppInfoCache.getInstance()).thenReturn(appInfoCache);
    when(oauthServerConfigurationMock.getPersistenceProcessor()).thenReturn(new PlainTextPersistenceProcessor());
    assertTrue(OAuth2Util.authenticateClient(clientId, clientSecret));
}
Also used : AppInfoCache(org.wso2.carbon.identity.oauth.cache.AppInfoCache) OAuthAppDO(org.wso2.carbon.identity.oauth.dao.OAuthAppDO) PlainTextPersistenceProcessor(org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 2 with PlainTextPersistenceProcessor

use of org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthConsumerDAOTest method testGetOAuthConsumerSecret.

@Test
public void testGetOAuthConsumerSecret() throws Exception {
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    PlainTextPersistenceProcessor processor = new PlainTextPersistenceProcessor();
    when(mockedServerConfig.getPersistenceProcessor()).thenReturn(processor);
    try (Connection connection1 = getConnection(DB_NAME)) {
        mockStatic(IdentityDatabaseUtil.class);
        when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection1);
        OAuthConsumerDAO consumerDAO = new OAuthConsumerDAO();
        assertEquals(consumerDAO.getOAuthConsumerSecret(CLIENT_ID), SECRET);
    }
}
Also used : PlainTextPersistenceProcessor(org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor) Connection(java.sql.Connection) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with PlainTextPersistenceProcessor

use of org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthConsumerDAOTest method testIsConsumerSecretExist.

@Test
public void testIsConsumerSecretExist() throws Exception {
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    PlainTextPersistenceProcessor processor = new PlainTextPersistenceProcessor();
    when(mockedServerConfig.getPersistenceProcessor()).thenReturn(processor);
    try (Connection connection1 = getConnection(DB_NAME)) {
        mockStatic(IdentityDatabaseUtil.class);
        when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection1);
        OAuthConsumerDAO consumerDAO = new OAuthConsumerDAO();
        assertEquals(consumerDAO.isConsumerSecretExist(CLIENT_ID, SECRET), true);
    }
}
Also used : PlainTextPersistenceProcessor(org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor) Connection(java.sql.Connection) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with PlainTextPersistenceProcessor

use of org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthConsumerDAOTest method testGetRequestToken.

@Test
public void testGetRequestToken() throws Exception {
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    PlainTextPersistenceProcessor processor = new PlainTextPersistenceProcessor();
    when(mockedServerConfig.getPersistenceProcessor()).thenReturn(processor);
    whenNew(Parameters.class).withNoArguments().thenReturn(mockedParameters);
    try (Connection connection3 = getConnection(DB_NAME)) {
        mockStatic(IdentityDatabaseUtil.class);
        when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection3);
        OAuthConsumerDAO consumerDAO = new OAuthConsumerDAO();
        assertEquals(consumerDAO.getRequestToken(REQ_TOKEN), mockedParameters);
    }
}
Also used : PlainTextPersistenceProcessor(org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor) Connection(java.sql.Connection) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with PlainTextPersistenceProcessor

use of org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthConsumerDAOTest method testGetOAuthTokenSecret.

@Test(dataProvider = "provideTokens")
public void testGetOAuthTokenSecret(String token, Boolean isAccessToken, String expected) throws Exception {
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(mockedServerConfig);
    PlainTextPersistenceProcessor processor = new PlainTextPersistenceProcessor();
    when(mockedServerConfig.getPersistenceProcessor()).thenReturn(processor);
    try (Connection connection3 = getConnection(DB_NAME)) {
        mockStatic(IdentityDatabaseUtil.class);
        when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection3);
        OAuthConsumerDAO consumerDAO = new OAuthConsumerDAO();
        assertEquals(consumerDAO.getOAuthTokenSecret(token, isAccessToken), expected);
    }
}
Also used : PlainTextPersistenceProcessor(org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor) Connection(java.sql.Connection) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PlainTextPersistenceProcessor (org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor)26 Test (org.testng.annotations.Test)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 Connection (java.sql.Connection)18 SQLException (java.sql.SQLException)7 Matchers.anyString (org.mockito.Matchers.anyString)4 AppInfoCache (org.wso2.carbon.identity.oauth.cache.AppInfoCache)4 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)4 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 OAuthCacheKey (org.wso2.carbon.identity.oauth.cache.OAuthCacheKey)2 OAuthAppDAO (org.wso2.carbon.identity.oauth.dao.OAuthAppDAO)2 OAuth2TokenValidationRequestDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationRequestDTO)2 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)2 AfterTest (org.testng.annotations.AfterTest)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 OAuthConsumerDAO (org.wso2.carbon.identity.oauth.dao.OAuthConsumerDAO)1 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)1 OAuth2ClientApplicationDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2ClientApplicationDTO)1