use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoListApiEnabledAuthInvalidSigned.
public void testRepoListApiEnabledAuthInvalidSigned() {
Request mockRequest = mock(Request.class);
ApiService mockApiService = mock(ApiService.class);
when(mockApiService.validateRequest("test", "test", "pub=test", ApiService.HmacType.SHA1)).thenReturn(false);
ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, null, null, null, null, new Helpers(), new LoggerWrapper());
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = true;
when(mockRequest.queryParams("pub")).thenReturn("test");
when(mockRequest.queryParams("sig")).thenReturn("test");
RepoResultApiResponse apiResponse = apiRouteService.repoList(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
assertThat(apiResponse.getRepoResultList()).isNull();
assertThat(apiResponse.isSucessful()).isFalse();
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepoAddMissingRepoPassword.
public void testRepoAddMissingRepoPassword() {
Request mockRequest = mock(Request.class);
SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
ApiRouteService apiRouteService = new ApiRouteService(null, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
apiRouteService.apiEnabled = true;
apiRouteService.apiAuth = false;
when(mockRequest.queryParams("reponame")).thenReturn("test");
when(mockRequest.queryParams("repourl")).thenReturn("test");
when(mockRequest.queryParams("repotype")).thenReturn("test");
when(mockRequest.queryParams("repousername")).thenReturn("test");
ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("repopassword is a required parameter");
assertThat(apiResponse.isSucessful()).isFalse();
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class CodeRouteServiceTest method testGetCodeWithParamsWithMatch.
public void testGetCodeWithParamsWithMatch() {
var request = mock(Request.class);
var response = mock(Response.class);
var indexService = mock(IndexService.class);
var highlight = mock(Highlight.class);
var codeRouteService = new CodeRouteService(indexService, new Helpers(), new SQLiteRepo(), new Data(), null, null, null, null, highlight);
var codeResult = new CodeResult(new ArrayList<>(), new ArrayList<>());
codeResult.setLines("100");
codeResult.setLanguageName("LanguageName");
codeResult.setMd5hash("md5hash");
codeResult.setRepoName("myRepo");
codeResult.setRepoLocation("repoLocation");
codeResult.setCodeOwner("codeOwner");
codeResult.setDisplayLocation("myDisplayLocation");
when(request.params(":codeid")).thenReturn("MATCH-MOCK");
when(indexService.getCodeResultByCodeId("MATCH-MOCK")).thenReturn(codeResult);
when(highlight.highlightCodeResult(any())).thenReturn(new HashMap<>() {
{
put("codeValue", "");
}
});
var map = codeRouteService.getCode(request, response);
assertThat(map.get("codePath")).isEqualTo("myDisplayLocation");
assertThat(map.get("codeLength")).isEqualTo("100");
assertThat(map.get("languageName")).isEqualTo("LanguageName");
assertThat(map.get("md5Hash")).isEqualTo("md5hash");
assertThat(map.get("repoName")).isEqualTo("myRepo");
assertThat(map.get("highlight")).isEqualTo(true);
assertThat(map.get("repoLocation")).isEqualTo("repoLocation");
// TODO depends on the highlighter being used
assertThat(map.get("codeValue")).isEqualTo("");
assertThat(map.get("highligher")).isNotNull();
assertThat(map.get("codeOwner")).isEqualTo("codeOwner");
assertThat(map.get("owaspResults")).isNotNull();
assertThat(map.get("logoImage")).isNotNull();
assertThat(map.get("isCommunity")).isEqualTo(App.IS_COMMUNITY);
assertThat(map.get("estimatedCost")).isEqualTo(2395);
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiServiceTest method testCase2.
public void testCase2() {
var apiMock = mock(Api.class);
when(apiMock.getApiByPublicKey("publicKey")).thenReturn(Optional.of(new ApiResult(1, "publicKey", "privateKey", "", "")));
var service = new ApiService(apiMock, new Helpers());
var actual = service.validateRequest("publicKey", "1577b8c8f5781bf2817a45bfb47ded066c579c37", "testmessage1", ApiService.HmacType.SHA1);
assertTrue(actual);
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiServiceTest method testCase1.
public void testCase1() {
var apiMock = mock(Api.class);
when(apiMock.getApiByPublicKey("publicKey")).thenReturn(Optional.of(new ApiResult(1, "publicKey", "privateKey", "", "")));
var service = new ApiService(apiMock, new Helpers());
var actual = service.validateRequest("publicKey", "e15db69d711f0f25ce07a9c11ebebe821e6fc312", "", ApiService.HmacType.SHA1);
assertTrue(actual);
}
Aggregations