Search in sources :

Example 1 with Api

use of com.searchcode.app.dao.Api in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestCorrectHmacMethodSha1.

public void testValidateRequestCorrectHmacMethodSha1() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(new ApiResult(1, "publicKey", "privateKey", "", ""));
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "3eb4cb7c8a30ac3814bbfae935cbe3c1f4f2acce", "stringtohmac", ApiService.HmacType.SHA1);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Api(com.searchcode.app.dao.Api)

Example 2 with Api

use of com.searchcode.app.dao.Api in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestNoMatchingKeyExpectFalse.

public void testValidateRequestNoMatchingKeyExpectFalse() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(null);
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "", "", ApiService.HmacType.SHA1);
    assertFalse(actual);
}
Also used : Api(com.searchcode.app.dao.Api)

Example 3 with Api

use of com.searchcode.app.dao.Api in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestInCorrectHmacMethodSha512.

public void testValidateRequestInCorrectHmacMethodSha512() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(new ApiResult(1, "publicKey", "privateKey", "", ""));
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "thisiswrong", "stringtohmac", ApiService.HmacType.SHA512);
    assertFalse(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Api(com.searchcode.app.dao.Api)

Example 4 with Api

use of com.searchcode.app.dao.Api in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestCorrectHmacMethodSha512.

public void testValidateRequestCorrectHmacMethodSha512() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(new ApiResult(1, "publicKey", "privateKey", "", ""));
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "8d8219101eecb1ae62e025c79379872d7461cf201a737893afc172aa9c98c505c7d1f4d864d9adbc17f8e2694fb0287fb7533e942c34589fc2daefc068e0cad3", "stringtohmac", ApiService.HmacType.SHA512);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Api(com.searchcode.app.dao.Api)

Example 5 with Api

use of com.searchcode.app.dao.Api in project searchcode-server by boyter.

the class ApiServiceTest method testValidateRequestCorrectHmacMethod.

public void testValidateRequestCorrectHmacMethod() {
    Api apiMock = mock(Api.class);
    when(apiMock.getApiByPublicKey("publicKey")).thenReturn(new ApiResult(1, "publicKey", "privateKey", "", ""));
    ApiService service = new ApiService(apiMock);
    boolean actual = service.validateRequest("publicKey", "3eb4cb7c8a30ac3814bbfae935cbe3c1f4f2acce", "stringtohmac", ApiService.HmacType.SHA1);
    assertTrue(actual);
}
Also used : ApiResult(com.searchcode.app.model.ApiResult) Api(com.searchcode.app.dao.Api)

Aggregations

Api (com.searchcode.app.dao.Api)13 ApiResult (com.searchcode.app.model.ApiResult)10 Data (com.searchcode.app.dao.Data)1 Repo (com.searchcode.app.dao.Repo)1