Search in sources :

Example 16 with Helpers

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);
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 17 with Helpers

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");
}
Also used : Helpers(com.searchcode.app.util.Helpers) RepoResult(com.searchcode.app.model.RepoResult)

Example 18 with Helpers

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());
}
Also used : Helpers(com.searchcode.app.util.Helpers)

Example 19 with Helpers

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);
}
Also used : Helpers(com.searchcode.app.util.Helpers)

Example 20 with Helpers

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);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Helpers(com.searchcode.app.util.Helpers)

Aggregations

Helpers (com.searchcode.app.util.Helpers)53 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)32 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)31 Request (spark.Request)31 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)29 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)27 ApiResponse (com.searchcode.app.dto.api.ApiResponse)26 RepoResult (com.searchcode.app.model.RepoResult)12 ApiResult (com.searchcode.app.model.ApiResult)9 Data (com.searchcode.app.dao.Data)5 ValidatorResult (com.searchcode.app.model.ValidatorResult)4 IndexService (com.searchcode.app.service.index.IndexService)3 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 SQLiteMemoryDatabaseConfig (com.searchcode.app.config.SQLiteMemoryDatabaseConfig)2 SourceResult (com.searchcode.app.model.SourceResult)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CodeIndexDocument (com.searchcode.app.dto.CodeIndexDocument)1 CodeResult (com.searchcode.app.dto.CodeResult)1 SearchResult (com.searchcode.app.dto.SearchResult)1 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)1