Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit test cases #38

Merged
merged 5 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 95 additions & 38 deletions component/authenticator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,62 +43,58 @@
<version>${identity.extension.utils}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.api</artifactId>
<version>4.3.0</version>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.entitlement.common</artifactId>
<groupId>org.apache.rampart.wso2</groupId>
<artifactId>rampart-core</artifactId>
<version>${rampart.wso2.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.balana</groupId>
<artifactId>org.wso2.balana</artifactId>
<groupId>org.apache.rampart.wso2</groupId>
<artifactId>rampart-policy</artifactId>
<version>${rampart.wso2.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.core</artifactId>
<version>4.3.0</version>
<groupId>org.apache.rampart.wso2</groupId>
<artifactId>rampart-trust</artifactId>
<version>${rampart.wso2.version}</version>
</dependency>
<!--Test Dependencies-->
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.core</artifactId>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-testng -->
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.base</artifactId>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.core.services</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.application.common</artifactId>
</dependency>
<dependency>
<groupId>org.apache.axis2.transport</groupId>
<artifactId>axis2-transport-mail</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity</groupId>
<artifactId>org.wso2.carbon.identity.mgt</artifactId>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
Expand Down Expand Up @@ -139,6 +135,67 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<!--<minimum>0.60</minimum>-->
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,14 @@ protected void processAuthenticationResponse(HttpServletRequest request,
.valueOf(context.getProperty(TOTPAuthenticatorConstants.ENABLE_TOTP).toString())) {
//adds the claims to the profile if the user enrol and continued.
Map<String, String> claims = new HashMap<>();
claims.put(TOTPAuthenticatorConstants.SECRET_KEY_CLAIM_URL,
context.getProperty(TOTPAuthenticatorConstants.SECRET_KEY_CLAIM_URL).toString());
claims.put(TOTPAuthenticatorConstants.QR_CODE_CLAIM_URL,
context.getProperty(TOTPAuthenticatorConstants.QR_CODE_CLAIM_URL).toString());
if (context.getProperty(TOTPAuthenticatorConstants.SECRET_KEY_CLAIM_URL) != null) {
claims.put(TOTPAuthenticatorConstants.SECRET_KEY_CLAIM_URL,
context.getProperty(TOTPAuthenticatorConstants.SECRET_KEY_CLAIM_URL).toString());
}
if (context.getProperty(TOTPAuthenticatorConstants.QR_CODE_CLAIM_URL) != null) {
claims.put(TOTPAuthenticatorConstants.QR_CODE_CLAIM_URL,
context.getProperty(TOTPAuthenticatorConstants.QR_CODE_CLAIM_URL).toString());
}
try {
TOTPKeyGenerator.addTOTPClaimsAndRetrievingQRCodeURL(claims, username, context);
} catch (TOTPException e) {
Expand Down Expand Up @@ -360,17 +364,23 @@ public String getName() {
* @return true, if token is generated successfully
*/
private boolean generateTOTPToken(AuthenticationContext context) {
String username = context.getProperty("username").toString();
try {
TOTPTokenGenerator.generateTOTPTokenLocal(username, context);
if (log.isDebugEnabled()) {
log.debug("TOTP Token is generated");
}
} catch (TOTPException e) {
log.error("Error when generating the totp token", e);
return false;
}
return true;
String username;
if (context.getProperty("username") == null) {
log.error("No username found in the authentication context.");
return false;
} else {
username = context.getProperty("username").toString();
try {
TOTPTokenGenerator.generateTOTPTokenLocal(username, context);
if (log.isDebugEnabled()) {
log.debug("TOTP Token is generated");
}
} catch (TOTPException e) {
log.error("Error when generating the totp token", e);
return false;
}
}
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,23 @@ public static String decrypt(String cipherText) throws CryptoException {
* @return encoding method
*/
public static String getEncodingMethod(String tenantDomain, AuthenticationContext context) {
String encodingMethod;
String encodingMethod = null;
if (tenantDomain.equals(TOTPAuthenticatorConstants.SUPER_TENANT_DOMAIN)) {
encodingMethod = String.valueOf(getTOTPParameters().get(TOTPAuthenticatorConstants.ENCODING_METHOD));
} else {
Object getPropertiesFromIdentityConfig = context
.getProperty(TOTPAuthenticatorConstants.GET_PROPERTY_FROM_IDENTITY_CONFIG);
if (getPropertiesFromIdentityConfig == null) {
encodingMethod = context.getProperty(TOTPAuthenticatorConstants.ENCODING_METHOD).toString();
if (context.getProperty(TOTPAuthenticatorConstants.ENCODING_METHOD) != null) {
encodingMethod = context.getProperty(TOTPAuthenticatorConstants.ENCODING_METHOD).toString();
}
} else {
encodingMethod = String.valueOf(
IdentityHelperUtil.getAuthenticatorParameters(TOTPAuthenticatorConstants.AUTHENTICATOR_NAME)
.get(TOTPAuthenticatorConstants.ENCODING_METHOD));
if (IdentityHelperUtil.getAuthenticatorParameters(TOTPAuthenticatorConstants.AUTHENTICATOR_NAME)
.get(TOTPAuthenticatorConstants.ENCODING_METHOD) != null) {
encodingMethod = String.valueOf(
IdentityHelperUtil.getAuthenticatorParameters(TOTPAuthenticatorConstants.AUTHENTICATOR_NAME)
.get(TOTPAuthenticatorConstants.ENCODING_METHOD));
}
}
}
if (TOTPAuthenticatorConstants.BASE64.equals(encodingMethod)) {
Expand Down
Loading