use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiRouteServiceTest method testRepositoryIndexApiNoMatchingRepo.
public void testRepositoryIndexApiNoMatchingRepo() {
JobService mockJobService = mock(JobService.class);
Request mockRequest = mock(Request.class);
SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
when(mockJobService.forceEnqueue(Matchers.anyObject())).thenReturn(true);
when(mockRequest.queryParams("repoUrl")).thenReturn("test");
when(mockSQLiteRepo.getRepoByUrl(any())).thenReturn(Optional.empty());
ApiRouteService apiRouteService = new ApiRouteService(null, mockJobService, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
apiRouteService.apiEnabled = true;
ApiResponse apiResponse = apiRouteService.repositoryIndex(mockRequest, null);
assertThat(apiResponse.getMessage()).isEqualTo("Was unable to find repository test");
assertThat(apiResponse.isSucessful()).isEqualTo(false);
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class MySQLRepoTest method testGetRepoByUrlCache.
public void testGetRepoByUrlCache() {
if (Singleton.getHelpers().isStandaloneInstance())
return;
var cache = CacheSingleton.getRepoResultCache();
cache.put("d.m.boyter", Optional.of(new RepoResult().setRowId(999).setName("ZeName").setUrl("boyter")));
var newSource = new MySQLRepo(Singleton.getDatabaseConfig(), new Helpers(), Singleton.getLogger(), cache);
var result = newSource.getRepoByUrl("boyter");
assertThat(result.get().getRowId()).isEqualTo(999);
assertThat(result.get().getName()).isEqualTo("ZeName");
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiServiceTest method testCreateKeys.
public void testCreateKeys() {
var apiMock = mock(Api.class);
when(apiMock.saveApi(anyObject())).thenReturn(true);
var service = new ApiService(apiMock, new Helpers());
var actual = service.createKeys();
assertNotNull(actual);
assertEquals(-1, actual.getRowId());
assertTrue(actual.getPublicKey().startsWith("APIK-"));
assertEquals(32, actual.getPublicKey().length());
assertEquals(32, actual.getPrivateKey().length());
assertEquals("", actual.getData());
assertEquals("", actual.getLastUsed());
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiServiceTest method testValidateRequestNoMatchingKeyExpectFalse.
public void testValidateRequestNoMatchingKeyExpectFalse() {
var apiMock = mock(Api.class);
when(apiMock.getApiByPublicKey("publicKey")).thenReturn(Optional.empty());
var service = new ApiService(apiMock, new Helpers());
var actual = service.validateRequest("publicKey", "", "", ApiService.HmacType.SHA1);
assertFalse(actual);
}
use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.
the class ApiServiceTest method testValidateRequestCorrectHmacMethodSha512.
public void testValidateRequestCorrectHmacMethodSha512() {
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", "8d8219101eecb1ae62e025c79379872d7461cf201a737893afc172aa9c98c505c7d1f4d864d9adbc17f8e2694fb0287fb7533e942c34589fc2daefc068e0cad3", "stringtohmac", ApiService.HmacType.SHA512);
assertTrue(actual);
}
Aggregations