Skip to content

Commit

Permalink
Merge pull request #1700 from anup-nehe/develop
Browse files Browse the repository at this point in the history
MOSIP-37889 added invalid token with jwt
  • Loading branch information
mohanachandran-s authored Dec 16, 2024
2 parents d23400c + c5b3db6 commit a5d0eda
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class BaseTestCase {
public String regProcCookie = null;
public String regProCookie = null;
public String regAdminCookie = null;
public String invalidcookie = "anyRandomString";
public String registrationOfficerCookie = null;
public String regSupervisorCookie = null;
public String zonalAdminCookie = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.mosip.testrig.apirig.utils;

import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.Base64.Encoder;
import java.util.Date;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import org.json.simple.JSONObject;

Expand All @@ -16,6 +23,7 @@ public class KernelAuthentication extends BaseTestCase {
String folder = "kernel";
String cookie;
static String dataKey = "response";
static String encodeBase64 ="";
static String errorKey = "errors";
static Map<String, String> tokens = new HashMap<>();
CommonLibrary clib = new CommonLibrary();
Expand Down Expand Up @@ -171,9 +179,12 @@ public String getTokenByRole(String role, String tokenType) {
if (!kernelCmnLib.isValidToken(invalidBatchJobToken))
invalidBatchJobToken = kernelAuthLib.getPreRegInvalidToken();
return invalidBatchJobToken;

case "invalid":
return "anyRandomString";
case "invalidtoken":
String encodingToken = "AnyRandomString-ToCreate-Jwt";
invalidcookie = kernelAuthLib.encodeBase64(encodingToken);
return invalidcookie;
case "regAdmin":
if (!kernelCmnLib.isValidToken(regAdminCookie))
regAdminCookie = kernelAuthLib.getAuthForRegistrationAdmin();
Expand Down Expand Up @@ -781,5 +792,20 @@ public String getAuthForAutoUser() {
cookie = reponse.getCookie(GlobalConstants.AUTHORIZATION);
return cookie;
}

@SuppressWarnings("unchecked")
public String encodeBase64(String value) {
String secret = value;
// Create the token
String token = JWT.create()
.withSubject("user123")
.withIssuer("example.com")
.withClaim("role", "admin")
.withIssuedAt(new Date())
.withExpiresAt(new Date(System.currentTimeMillis() + 3600000))
.sign(Algorithm.HMAC256(secret));
System.out.println("Generated Token: " + token);
return token;
}

}

0 comments on commit a5d0eda

Please sign in to comment.