@Test public void requestAllBlocklists_noMatch() throws Exception { Advertiser advertiser = new Advertiser("a-cool-advertiser.com"); AdvertiserService aService = mock(AdvertiserService.class); when(aService.getAdvertiserList()).thenReturn(Collections.<Advertiser>singletonList(advertiser)); SupplySidePlatform ssp = new SupplySidePlatform("supply-side-platform-organization", "supply.platform.com", "our shared secret".getBytes()); IdentificationService iService = mock(IdentificationService.class); when(iService.getOrganizationIdentifier()).thenReturn("organization-identifier"); when(iService.getServiceEndpoints()).thenReturn(Collections.<SupplySidePlatform>singletonList(ssp)); AdvertiserBlocklistRequester test = new AdvertiserBlocklistRequester(aService, iService) { @Override AdvertiserBlocklistResponse makeRequest(SupplySidePlatform ssp, String request) { return null; } }; test.requestAllBlocklists(); verify(aService).getAdvertiserList(); verify(aService, never()).replaceBlocklists(null, null); }
public void requestAllBlocklists() { Collection<Advertiser> advertisers = advertiserService.getAdvertiserList(); if (advertisers == null || advertisers.isEmpty()) { logger.info("Unable to sync blocklists with supply-side platforms; no advertisers returned from AdvertiserService#getAdvertiserList()."); return; } for(SupplySidePlatform ssp : identificationService.getServiceEndpoints()) { String organization = ssp.getDemandSideName(); if (organization == null) { organization = identificationService.getOrganizationIdentifier(); } Identification dsp = new Identification(organization); AdvertiserBlocklistRequest request = new AdvertiserBlocklistRequest(dsp, advertisers); try { request.sign(ssp.getSharedSecret(), REQUEST_TRANSFORM); } catch (IOException e) { logger.error("Unable to sign json request for ["+ssp.getOrganization()+"] due to exception", e); continue; } AdvertiserBlocklistResponse response = null; try { response = makeRequest(ssp, REQUEST_TRANSFORM.toJSON(request)); if (response != null) { if (response.verify(ssp.getSharedSecret(), RESPONSE_TRANSFORM)) { advertiserService.replaceBlocklists(ssp, response.getAdvertisers()); } else { logger.error("Verification of response from ["+ssp.getOrganization()+"] failed"); continue; } } } catch (IOException e) { logger.error("Unable to verify json response from ["+ssp.getOrganization()+"] due to exception", e); continue; } } }
AdvertiserBlocklistRequester { public void requestAllBlocklists() { Collection<Advertiser> advertisers = advertiserService.getAdvertiserList(); if (advertisers == null || advertisers.isEmpty()) { logger.info("Unable to sync blocklists with supply-side platforms; no advertisers returned from AdvertiserService#getAdvertiserList()."); return; } for(SupplySidePlatform ssp : identificationService.getServiceEndpoints()) { String organization = ssp.getDemandSideName(); if (organization == null) { organization = identificationService.getOrganizationIdentifier(); } Identification dsp = new Identification(organization); AdvertiserBlocklistRequest request = new AdvertiserBlocklistRequest(dsp, advertisers); try { request.sign(ssp.getSharedSecret(), REQUEST_TRANSFORM); } catch (IOException e) { logger.error("Unable to sign json request for ["+ssp.getOrganization()+"] due to exception", e); continue; } AdvertiserBlocklistResponse response = null; try { response = makeRequest(ssp, REQUEST_TRANSFORM.toJSON(request)); if (response != null) { if (response.verify(ssp.getSharedSecret(), RESPONSE_TRANSFORM)) { advertiserService.replaceBlocklists(ssp, response.getAdvertisers()); } else { logger.error("Verification of response from ["+ssp.getOrganization()+"] failed"); continue; } } } catch (IOException e) { logger.error("Unable to verify json response from ["+ssp.getOrganization()+"] due to exception", e); continue; } } } }
AdvertiserBlocklistRequester { public void requestAllBlocklists() { Collection<Advertiser> advertisers = advertiserService.getAdvertiserList(); if (advertisers == null || advertisers.isEmpty()) { logger.info("Unable to sync blocklists with supply-side platforms; no advertisers returned from AdvertiserService#getAdvertiserList()."); return; } for(SupplySidePlatform ssp : identificationService.getServiceEndpoints()) { String organization = ssp.getDemandSideName(); if (organization == null) { organization = identificationService.getOrganizationIdentifier(); } Identification dsp = new Identification(organization); AdvertiserBlocklistRequest request = new AdvertiserBlocklistRequest(dsp, advertisers); try { request.sign(ssp.getSharedSecret(), REQUEST_TRANSFORM); } catch (IOException e) { logger.error("Unable to sign json request for ["+ssp.getOrganization()+"] due to exception", e); continue; } AdvertiserBlocklistResponse response = null; try { response = makeRequest(ssp, REQUEST_TRANSFORM.toJSON(request)); if (response != null) { if (response.verify(ssp.getSharedSecret(), RESPONSE_TRANSFORM)) { advertiserService.replaceBlocklists(ssp, response.getAdvertisers()); } else { logger.error("Verification of response from ["+ssp.getOrganization()+"] failed"); continue; } } } catch (IOException e) { logger.error("Unable to verify json response from ["+ssp.getOrganization()+"] due to exception", e); continue; } } } AdvertiserBlocklistRequester(AdvertiserService advertiserService,
                                        IdentificationService identificationService); }
AdvertiserBlocklistRequester { public void requestAllBlocklists() { Collection<Advertiser> advertisers = advertiserService.getAdvertiserList(); if (advertisers == null || advertisers.isEmpty()) { logger.info("Unable to sync blocklists with supply-side platforms; no advertisers returned from AdvertiserService#getAdvertiserList()."); return; } for(SupplySidePlatform ssp : identificationService.getServiceEndpoints()) { String organization = ssp.getDemandSideName(); if (organization == null) { organization = identificationService.getOrganizationIdentifier(); } Identification dsp = new Identification(organization); AdvertiserBlocklistRequest request = new AdvertiserBlocklistRequest(dsp, advertisers); try { request.sign(ssp.getSharedSecret(), REQUEST_TRANSFORM); } catch (IOException e) { logger.error("Unable to sign json request for ["+ssp.getOrganization()+"] due to exception", e); continue; } AdvertiserBlocklistResponse response = null; try { response = makeRequest(ssp, REQUEST_TRANSFORM.toJSON(request)); if (response != null) { if (response.verify(ssp.getSharedSecret(), RESPONSE_TRANSFORM)) { advertiserService.replaceBlocklists(ssp, response.getAdvertisers()); } else { logger.error("Verification of response from ["+ssp.getOrganization()+"] failed"); continue; } } } catch (IOException e) { logger.error("Unable to verify json response from ["+ssp.getOrganization()+"] due to exception", e); continue; } } } AdvertiserBlocklistRequester(AdvertiserService advertiserService,
                                        IdentificationService identificationService); void requestAllBlocklists(); }
AdvertiserBlocklistRequester { public void requestAllBlocklists() { Collection<Advertiser> advertisers = advertiserService.getAdvertiserList(); if (advertisers == null || advertisers.isEmpty()) { logger.info("Unable to sync blocklists with supply-side platforms; no advertisers returned from AdvertiserService#getAdvertiserList()."); return; } for(SupplySidePlatform ssp : identificationService.getServiceEndpoints()) { String organization = ssp.getDemandSideName(); if (organization == null) { organization = identificationService.getOrganizationIdentifier(); } Identification dsp = new Identification(organization); AdvertiserBlocklistRequest request = new AdvertiserBlocklistRequest(dsp, advertisers); try { request.sign(ssp.getSharedSecret(), REQUEST_TRANSFORM); } catch (IOException e) { logger.error("Unable to sign json request for ["+ssp.getOrganization()+"] due to exception", e); continue; } AdvertiserBlocklistResponse response = null; try { response = makeRequest(ssp, REQUEST_TRANSFORM.toJSON(request)); if (response != null) { if (response.verify(ssp.getSharedSecret(), RESPONSE_TRANSFORM)) { advertiserService.replaceBlocklists(ssp, response.getAdvertisers()); } else { logger.error("Verification of response from ["+ssp.getOrganization()+"] failed"); continue; } } } catch (IOException e) { logger.error("Unable to verify json response from ["+ssp.getOrganization()+"] due to exception", e); continue; } } } AdvertiserBlocklistRequester(AdvertiserService advertiserService,
                                        IdentificationService identificationService); void requestAllBlocklists(); static final String SPRING_NAME; }