diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c30d3dc4..3b0cdcf3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,7 @@ jobs: rm -f secret_key.asc # gpg --list-secret-keys + # Generate settings.xml with Maven repository credentials - name: Create settings.xml run: | diff --git a/README.md b/README.md index a6a2a2db..b4c3ee2b 100644 --- a/README.md +++ b/README.md @@ -263,3 +263,4 @@ CmpList cmpList = loader.cmpList(cmpListContent); ## Contributing Here you can find the [contributing guide](CONTRIBUTING.md) to help maintain and update the library. This library is managed by the Code Libraries Subgroup of the Global Privacy Working Group at the IAB Tech Lab. To join the group, please reach out to support@iabtechlab.com. + diff --git a/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java b/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java index a85a5e25..b4f8cba3 100644 --- a/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java +++ b/iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java @@ -359,7 +359,7 @@ protected String encodeModel(Map sections) { } protected Map decodeModel(String str) { - if (str == null || str.isEmpty() || str.startsWith("D")) { + if (str == null || str.isEmpty() || str.startsWith("DB")) { Map sections = new HashMap<>(); if (str != null && !str.isEmpty()) { diff --git a/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/GppModelTest.java b/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/GppModelTest.java index 9a6e9609..d1890a59 100644 --- a/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/GppModelTest.java +++ b/iabgpp-encoder/src/test/java/com/iab/gpp/encoder/GppModelTest.java @@ -69,20 +69,6 @@ public void testEncodeDefault() { } - @Test - public void testDecodingException() { - Assertions.assertThrows(DecodingException.class, () -> { - new GppModel("invalid gpp string").getHeader(); - }); - } - - @Test() - public void testDecodeGarbage() { - Assertions.assertThrows(DecodingException.class, () -> { - new GppModel("z").getUsCtSection(); - }); - } - @Test public void testEncodeDefaultAll() { GppModel gppModel = new GppModel(); @@ -132,7 +118,6 @@ public void testEncodeDefaultAll() { gppModel.setFieldValue(UsTn.NAME, UsTxField.VERSION, UsTx.VERSION); - Assertions.assertEquals(true, gppModel.hasSection(TcfEuV2.NAME)); Assertions.assertEquals(true, gppModel.hasSection(TcfCaV1.NAME)); Assertions.assertEquals(true, gppModel.hasSection(UspV1.NAME)); @@ -155,9 +140,22 @@ public void testEncodeDefaultAll() { String gppString = gppModel.encode(); Assertions.assertEquals( - "DBACOdM~CPSG_8APSG_8AAAAAAENAACAAAAAAAAAAAAAAAAAAAAA.QAAA.IAAA~BPSG_8APSG_8AAAAAAENAACAAAAAAAAAAAAAAAAAAA.YAAAAAAAAAA~1---~BAAAAAAAAABA.QA~BAAAAABA.QA~BAAAABA~BAAAAEA.QA~BAAAAAQA~BAAAAAEA.QA~BAAAAABA~BAAAAABA.QA~BAAAAAABAA.QA~BAAAAAQA.QA~BAAAAAABAA.QA~BAAAAAQA.QA~BAAAAAQA.QA~BAAAAABA.QA~BAAAAAAAQA.QA~BAAAAAQA.QA", - gppString); + "DBACOdM~CPSG_8APSG_8AAAAAAENAACAAAAAAAAAAAAAAAAAAAAA.QAAA.IAAA~BPSG_8APSG_8AAAAAAENAACAAAAAAAAAAAAAAAAAAA.YAAAAAAAAAA~1---~BAAAAAAAAABA.QA~BAAAAABA.QA~BAAAABA~BAAAAEA.QA~BAAAAAQA~BAAAAAEA.QA~BAAAAABA~BAAAAABA.QA~BAAAAAABAA.QA~BAAAAAQA.QA~BAAAAAABAA.QA~BAAAAAQA.QA~BAAAAAQA.QA~BAAAAABA.QA~BAAAAAAAQA.QA~BAAAAAQA.QA", + gppString); + } + @Test + public void testDecodingException() { + Assertions.assertThrows(DecodingException.class, () -> { + new GppModel("invalid gpp string").getHeader(); + }); + } + + @Test() + public void testDecodeGarbage() { + Assertions.assertThrows(DecodingException.class, () -> { + new GppModel("z").getUsCtSection(); + }); } @Test @@ -821,6 +819,17 @@ public void testDecodingEmptyString() { gppModel.setFieldValue("uspv1", UspV1Field.NOTICE, 'Y'); Assertions.assertEquals("DBABTA~1Y--", gppModel.encode()); } + + @Test + public void testDecodingExceptionValidStringButNotGPP() { + try { + GppModel gppModel = new GppModel("DP48G0AP48G0AEsACCPLAkEgAAAAAEPgAB5YAAAQaQD2F2K2kKFkPCmQWYAQBCijYEAhQAAAAkCBIAAgAUgQAgFIIAgAIFAAAAAAAAAQEgCQAAQABAAAIACgAAAAAAIAAAAAAAQQAAAAAIAAAAAAAAEAAAAAAAQAAAAIAABEhCAAQQAEAAAAAAAQAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAgAA"); + gppModel.getHeader().getName(); + Assertions.fail("Expected LazyDecodingException"); + } catch (DecodingException e) { + + } + } }