Search in sources :

Example 21 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestCorrectHmacMethod.

public void testValidateRequestCorrectHmacMethod() {
    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", "3eb4cb7c8a30ac3814bbfae935cbe3c1f4f2acce", "stringtohmac", ApiService.HmacType.SHA1);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Helpers(com.searchcode.app.util.Helpers)

Example 22 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestCorrectHmac.

public void testValidateRequestCorrectHmac() {
    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", "3eb4cb7c8a30ac3814bbfae935cbe3c1f4f2acce", "stringtohmac", ApiService.HmacType.SHA1);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Helpers(com.searchcode.app.util.Helpers)

Example 23 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestCorrectHmacMethodSha1.

public void testValidateRequestCorrectHmacMethodSha1() {
    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", "3eb4cb7c8a30ac3814bbfae935cbe3c1f4f2acce", "stringtohmac", ApiService.HmacType.SHA1);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Helpers(com.searchcode.app.util.Helpers)

Example 24 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestInCorrectHmacMethodSha512.

public void testValidateRequestInCorrectHmacMethodSha512() {
    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", "thisiswrong", "stringtohmac", ApiService.HmacType.SHA512);
    assertFalse(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Helpers(com.searchcode.app.util.Helpers)

Example 25 with Helpers

use of com.searchcode.app.util.Helpers in project searchcode-server by boyter.

the class ApiServiceTest method testCase3.

public void testCase3() {
    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", "0cb1ae7ab0db51dd82c4d29000523e643d8a1fcb", "?pub=publicKey&reponame=test&repourl=http://github.com/&reposource=&repobranch=master", ApiService.HmacType.SHA1);
    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