use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiTest method testSaveRetrieve.
public void testSaveRetrieve() {
String randomApiString = this.getRandomString();
this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
this.api.deleteApiByPublicKey(randomApiString);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiTest method testMultipleRetrieveCache.
public void testMultipleRetrieveCache() {
String randomApiString = this.getRandomString();
this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
for (int i = 0; i < 500; i++) {
ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
}
this.api.deleteApiByPublicKey(randomApiString);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiTest method testGetAllApi.
public void testGetAllApi() {
String randomApi1 = this.getRandomString();
String randomApi2 = this.getRandomString();
this.api.saveApi(new ApiResult(0, randomApi1, "privateKey", "", ""));
this.api.saveApi(new ApiResult(0, randomApi2, "privateKey", "", ""));
assertThat(this.api.getAllApi().size()).isEqualTo(2);
this.api.deleteApiByPublicKey(randomApi1);
this.api.deleteApiByPublicKey(randomApi2);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiServiceTest method testCase2.
public void testCase2() {
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", "1577b8c8f5781bf2817a45bfb47ded066c579c37", "testmessage1", ApiService.HmacType.SHA1);
assertTrue(actual);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiServiceTest method testValidateRequestInCorrectHmac.
public void testValidateRequestInCorrectHmac() {
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", "incorrecthmac", "stringtohmac", ApiService.HmacType.SHA1);
assertFalse(actual);
}
Aggregations