Ajuste TTL e adicionado teste de token gerado pelo serviço
parent
482261845e
commit
61aef7b8cb
|
@ -23,7 +23,7 @@ public class SecurityEmpresaToken {
|
||||||
private static Logger log = Logger.getLogger(SecurityEmpresaToken.class);
|
private static Logger log = Logger.getLogger(SecurityEmpresaToken.class);
|
||||||
|
|
||||||
private String secret = "#KO&Fm4_k.sU9M8`6Mx'F\\\"H:*Qxu]6F4r,)JmZ2Jwafd)I.2[RET'1:)VQ6mG9,";
|
private String secret = "#KO&Fm4_k.sU9M8`6Mx'F\\\"H:*Qxu]6F4r,)JmZ2Jwafd)I.2[RET'1:)VQ6mG9,";
|
||||||
private static final Duration ttl = Duration.ofHours(24);
|
private static final Duration ttl = Duration.ofDays(7);
|
||||||
|
|
||||||
private Gson gson = new Gson();
|
private Gson gson = new Gson();
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,31 @@ public class SecurityEmpresaTokenTest {
|
||||||
log.info("[ END ]");
|
log.info("[ END ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Token() throws Exception {
|
||||||
|
// license request -> token request -> token response -> license
|
||||||
|
|
||||||
|
Integer empresaId = 1313;
|
||||||
|
String cnpj = "00073778000120";
|
||||||
|
|
||||||
|
SecurityEmpresaToken security = new SecurityEmpresaToken();
|
||||||
|
|
||||||
|
final String bodyRequest = security.bodyRequestGenerate(empresaId, cnpj);
|
||||||
|
final String request = security.requestGenerate(bodyRequest);
|
||||||
|
|
||||||
|
final String reponse = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI4ZTY2MGVmOTQwMGRlNjU2MmQ1MjljZTVkZDMyZDU0NmM2OGU5YTk0NTUwYjUyNzc4MDhjNWIxMjgzNzkwNjVlNzI0NWU2ZTMxNzBjMTQ2ZGVlOWUyNGQwZjc1YzMwYTVmM2JlYmY5NjY0YzZiNWNiYjU3NTk1NzVmOGYzMTk4OTljNmVmODNkZDc3NmI4YjM2MGM1NDE3N2RhMzFkMDAzNTA5ZDFlIiwiZXhwIjoxNjk5NjQ5OTQ1LCJ1c2VySWQiOiJhZG0iLCJyb2xlIjoiUk9MRV9UT0tFTiJ9.0WFPKf6RcpPYle4Rgq_D-GScwhkw_Q4pmCvNCL_INfg";
|
||||||
|
|
||||||
|
final String license = security.tokenValidate(reponse);
|
||||||
|
final boolean valid = security.licenseValidate(license, empresaId, cnpj);
|
||||||
|
|
||||||
|
log.info("Body Request: " + bodyRequest);
|
||||||
|
log.info("Request: " + request);
|
||||||
|
log.info("License: " + license);
|
||||||
|
log.info("Valid: " + Boolean.toString(valid));
|
||||||
|
|
||||||
|
if (!valid) fail("Licença inválida");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_EmpresaNova() throws Exception {
|
public void test_EmpresaNova() throws Exception {
|
||||||
// license request -> token request -> token response -> license
|
// license request -> token request -> token response -> license
|
||||||
|
@ -75,14 +100,15 @@ public class SecurityEmpresaTokenTest {
|
||||||
|
|
||||||
final String bodyRequest = security.bodyRequestGenerate(empresaId, cnpj);
|
final String bodyRequest = security.bodyRequestGenerate(empresaId, cnpj);
|
||||||
final String request = security.requestGenerate(bodyRequest, ttl);
|
final String request = security.requestGenerate(bodyRequest, ttl);
|
||||||
|
|
||||||
|
log.info("Body Request: " + bodyRequest);
|
||||||
|
log.info("Request: " + request);
|
||||||
|
|
||||||
Thread.sleep(Duration.ofSeconds(10).toMillis());
|
Thread.sleep(Duration.ofSeconds(10).toMillis());
|
||||||
|
|
||||||
final String license = security.tokenValidate(request);
|
final String license = security.tokenValidate(request);
|
||||||
final boolean valid = security.licenseValidate(license, empresaId, cnpj);
|
final boolean valid = security.licenseValidate(license, empresaId, cnpj);
|
||||||
|
|
||||||
log.info("Body Request: " + bodyRequest);
|
|
||||||
log.info("Request: " + request);
|
|
||||||
log.info("License: " + license);
|
log.info("License: " + license);
|
||||||
log.info("Valid: " + Boolean.toString(valid));
|
log.info("Valid: " + Boolean.toString(valid));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue