Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #69 from tiki/release/1.0.3
Browse files Browse the repository at this point in the history
fix: hash ptrs before searching for them.
  • Loading branch information
mike-audi authored Apr 1, 2023
2 parents 1fd1ceb + 4a5c6ab commit 9040ec7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
license:
name: MIT
url: https://github.com/tiki/l0-index/blob/main/LICENSE
version: 1.0.2
version: 1.0.3
servers:
- url: https://index.l0.mytiki.com
paths:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.mytiki</groupId>
<artifactId>l0_index</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>jar</packaging>

<name>L0 Index</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import com.mytiki.l0_index.features.latest.title.TitleDO;
import com.mytiki.l0_index.features.latest.title.TitleService;
import com.mytiki.l0_index.features.latest.use.UseService;
import com.mytiki.l0_index.utilities.AOSignature;
import com.mytiki.l0_index.utilities.AOUse;
import com.mytiki.l0_index.utilities.B64;
import com.mytiki.l0_index.utilities.Decode;
import com.mytiki.l0_index.utilities.*;
import com.mytiki.spring_rest_api.ApiExceptionBuilder;
import jakarta.transaction.Transactional;
import org.bouncycastle.util.encoders.Base64;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.codec.Utf8;

import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -76,6 +77,7 @@ public LicenseDO insert(IndexAOReqLicense req, String appId, BlockDO block){

public LicenseAORspList list(LicenseAOReq req, String appId, Long pageToken, Integer maxResults){
LicenseAORspList rsp = new LicenseAORspList();
req.setPtrs(hashPtrs(req.getPtrs()));
List<LicenseDO> licenses = repository.search(req, appId, pageToken, maxResults);

if(pageToken == null && licenses.size() < maxResults)
Expand Down Expand Up @@ -160,4 +162,15 @@ public LicenseAORsp fetch(String transaction, String appId){
}
return rsp;
}


private List<String> hashPtrs(List<String> ptrs){
if(ptrs == null) return null;
List<String> rsp = new ArrayList<>(ptrs.size());
ptrs.forEach((ptr) -> {
byte[] hashBytes = Sha256.hash(ptr.getBytes(StandardCharsets.UTF_8));
rsp.add(Base64.toBase64String(hashBytes));
});
return rsp;
}
}
11 changes: 9 additions & 2 deletions src/test/java/LicenseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.mytiki.l0_index.features.latest.use.UseService;
import com.mytiki.l0_index.main.App;
import com.mytiki.l0_index.utilities.AOUse;
import com.mytiki.l0_index.utilities.Sha256;
import jakarta.transaction.Transactional;
import org.bouncycastle.util.encoders.Base64;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -27,6 +29,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -252,16 +255,20 @@ public void Test_List_Tag_Success(){
public void Test_List_Ptr_Success(){
String appId = UUID.randomUUID().toString();
BlockDO block = blockService.insert(UUID.randomUUID().toString(), "https://mytiki.com");

String ptr = UUID.randomUUID().toString();
String hashedPtr = Base64.toBase64String(Sha256.hash(ptr.getBytes(StandardCharsets.UTF_8)));

IndexAOReqTitle titleReq = new IndexAOReqTitle(UUID.randomUUID().toString(), UUID.randomUUID().toString(),
UUID.randomUUID().toString(), List.of(UUID.randomUUID().toString()));
hashedPtr, List.of(UUID.randomUUID().toString()));
TitleDO title = titleService.insert(titleReq, appId, block);
IndexAOReqLicense licenseReq = new IndexAOReqLicense(
UUID.randomUUID().toString(), UUID.randomUUID().toString(), title.getTransaction(),
List.of(new AOUse(UUID.randomUUID().toString(), null)), null);
service.insert(licenseReq, appId, block);

LicenseAOReq req = new LicenseAOReq();
req.setPtrs(List.of(titleReq.getPtr()));
req.setPtrs(List.of(ptr));
LicenseAORspList list = service.list(req, appId, null, 100);
assertEquals(list.getResults().size(), 1);
assertEquals(list.getResults().get(0).getId(), licenseReq.getTransaction());
Expand Down

0 comments on commit 9040ec7

Please sign in to comment.