Skip to content

Commit

Permalink
core: Fix validation test #TASK-4913
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Aug 31, 2023
1 parent 8abd155 commit 483d556
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.opencb.opencga.catalog.managers.StudyManager;
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.cellbase.CellBaseValidator;
import org.opencb.opencga.core.common.ExceptionUtils;
import org.opencb.opencga.core.common.UriUtils;
import org.opencb.opencga.core.config.storage.CellBaseConfiguration;
import org.opencb.opencga.core.config.storage.SampleIndexConfiguration;
Expand Down Expand Up @@ -564,7 +565,10 @@ public OpenCGAResult<Job> setCellbaseConfiguration(String project, CellBaseConfi
String annotationSaveId, String token)
throws CatalogException, StorageEngineException {
StopWatch stopwatch = StopWatch.createStarted();
return secureOperationByProject("configureCellbase", project, new ObjectMap(), token, engine -> {
return secureOperationByProject("configureCellbase", project, new ObjectMap()
.append("cellbaseConfiguration", cellbaseConfiguration)
.append("annotate", annotate)
.append("annotationSaveId", annotationSaveId), token, engine -> {
OpenCGAResult<Job> result = new OpenCGAResult<>();
result.setResultType(Job.class.getCanonicalName());
result.setResults(new ArrayList<>());
Expand Down Expand Up @@ -1237,6 +1241,8 @@ private <R> R secureTool(String toolId, boolean isOperation, ObjectMap params, S
if (exception != null) {
auditAttributes.append("errorType", exception.getClass());
auditAttributes.append("errorMessage", exception.getMessage());
auditAttributes.append("errorMessageFull", ExceptionUtils.prettyExceptionMessage(exception, false, true));
auditAttributes.append("exceptionStackTrace", ExceptionUtils.prettyExceptionStackTrace(exception));
status = new AuditRecord.Status(AuditRecord.Status.Result.ERROR,
new Error(-1, exception.getClass().getName(), exception.getMessage()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ private CellBaseConfiguration validate(boolean autoComplete) throws IOException
}
}
}
if (StringUtils.isEmpty(getToken())) {
String token = getToken();
if (StringUtils.isEmpty(token)) {
cellBaseConfiguration.setToken(null);
} else {
// Check it's supported
Expand All @@ -187,7 +188,7 @@ private CellBaseConfiguration validate(boolean autoComplete) throws IOException
// Check it's an actual token
DataAccessTokenManager tokenManager = new DataAccessTokenManager();
try {
tokenManager.decode(getToken());
tokenManager.decode(token);
} catch (JwtException e) {
throw new IllegalArgumentException("Malformed token for cellbase "
+ "url: '" + getURL() + "'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@ public void testToken() throws IOException {
public void testTokenNotSupported() throws IOException {
String token = System.getenv("CELLBASE_HGMD_TOKEN");
Assume.assumeTrue(StringUtils.isNotEmpty(token));
thrown.expectMessage("Token not supported");
CellBaseConfiguration validated = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.1", null, token), "hsapiens", "grch38", true);
Assert.assertNotNull(validated.getToken());
}

@Test
public void testTokenEmpty() throws IOException {
String token = "";
CellBaseConfiguration validated = CellBaseValidator.validate(new CellBaseConfiguration(ParamConstants.CELLBASE_URL, "v5.1", null, token), "hsapiens", "grch38", true);
Assert.assertNull(validated.getToken());
}

@Test
public void testMalformedToken() throws IOException {
thrown.expectMessage("Malformed token for cellbase");
Expand Down

0 comments on commit 483d556

Please sign in to comment.