Skip to content
Snippets Groups Projects
Commit cab9f81e authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Optimize BMA `/wot/certifiers-of/:search` and `/wot/certified-by/:search` - Close #1440

parent 9a08389c
No related branches found
No related tags found
1 merge request!1423[enh] Optimize BMA `/wot/certifiers-of/:search` and `/wot/certified-by/:search` - Close #1440
......@@ -743,6 +743,17 @@ export class FileDAL implements ServerDAO {
return await this.iindexDAL.getFromPubkeyOrUid(search);
}
async getWrittenIdtyByPubkeyForHashingAndIsMember(
pub: string
): Promise<{
uid: string;
created_on: string;
pub: string;
member: boolean;
} | null> {
return await this.iindexDAL.getFromPubkey(pub);
}
async getWrittenIdtyByPubkeyForRevocationCheck(
pubkey: string
): Promise<{
......
......@@ -132,9 +132,17 @@ export class WOTBinding extends AbstractController {
async certifiersOf(req: any): Promise<HttpCertifications> {
const search = await ParametersService.getSearchP(req);
const idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember(
search
)) as FullIindexEntry;
let idty: FullIindexEntry;
if (req.query.pubkey) {
idty = (await this.server.dal.getWrittenIdtyByPubkeyForHashingAndIsMember(
search
)) as FullIindexEntry;
}
else {
idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember(
search
)) as FullIindexEntry;
}
const certs = await this.server.dal.certsToTarget(
idty.pub,
IdentityDTO.getTargetHash(idty)
......@@ -229,9 +237,17 @@ export class WOTBinding extends AbstractController {
async certifiedBy(req: any): Promise<HttpCertifications> {
const search = await ParametersService.getSearchP(req);
const idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember(
search
)) as FullIindexEntry;
let idty: FullIindexEntry;
if (req.query.pubkey) {
idty = (await this.server.dal.getWrittenIdtyByPubkeyForHashingAndIsMember(
search
)) as FullIindexEntry;
}
else {
idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember(
search
)) as FullIindexEntry;
}
const certs = await this.server.dal.certsFrom(idty.pub);
const theCerts: HttpCertification[] = [];
for (const cert of certs) {
......
......@@ -192,6 +192,13 @@ describe("Identities collision", function() {
});
});
it('should have certifiers-of/:pubkey of cat giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
res.should.have.property('uid').equal('cat');
});
});
it('should have certifiers-of/tic giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/tic', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV');
......@@ -213,6 +220,13 @@ describe("Identities collision", function() {
});
});
it('should have certifiers-of/:pubkey of tic giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV');
res.should.have.property('uid').equal('tic');
});
});
it('should have certifiers-of/toc giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/toc', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo');
......@@ -234,6 +248,13 @@ describe("Identities collision", function() {
});
});
it('should have certifiers-of/:pubkey of toc giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo');
res.should.have.property('uid').equal('toc');
});
});
it('requirements of cat', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/requirements/cat', { json: true }), function(res:HttpRequirements) {
res.should.have.property('identities').be.an.Array;
......@@ -298,6 +319,13 @@ describe("Identities collision", function() {
});
});
it('should have certified-by/:pubkey of tic giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV');
res.should.have.property('uid').equal('tic');
});
});
it('should have certified-by/tac giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/tac', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
......@@ -308,6 +336,13 @@ describe("Identities collision", function() {
});
});
it('should have certified-by/:pubkey of tac giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
res.should.have.property('uid').equal('tac');
});
});
it('should have certified-by/cat giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/cat', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
......@@ -343,6 +378,13 @@ describe("Identities collision", function() {
});
});
it('should have certified-by/:pubkey of cat giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
res.should.have.property('uid').equal('cat');
});
});
it('requirements of man2', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/requirements/man2', { json: true }), function(res:HttpRequirements) {
res.should.have.property('identities').be.an.Array;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment