|
| 1 | +// Copyright 2025 The Nomulus Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package google.registry.tmch; |
| 16 | + |
| 17 | +import static com.google.common.truth.Truth.assertThat; |
| 18 | +import static google.registry.persistence.transaction.TransactionManagerFactory.tm; |
| 19 | +import static google.registry.util.RegistryEnvironment.PRODUCTION; |
| 20 | +import static google.registry.util.RegistryEnvironment.SANDBOX; |
| 21 | + |
| 22 | +import com.google.common.base.Splitter; |
| 23 | +import google.registry.model.smd.SignedMarkRevocationList; |
| 24 | +import google.registry.model.smd.SignedMarkRevocationListDao; |
| 25 | +import google.registry.model.tmch.ClaimsListDao; |
| 26 | +import google.registry.persistence.transaction.JpaTestExtensions; |
| 27 | +import google.registry.testing.FakeClock; |
| 28 | +import google.registry.util.RegistryEnvironment; |
| 29 | +import java.util.stream.Stream; |
| 30 | +import org.joda.time.DateTime; |
| 31 | +import org.junit.jupiter.api.BeforeEach; |
| 32 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 33 | +import org.junit.jupiter.params.ParameterizedTest; |
| 34 | +import org.junit.jupiter.params.provider.Arguments; |
| 35 | +import org.junit.jupiter.params.provider.MethodSource; |
| 36 | + |
| 37 | +public class RstTmchUtilsIntTest { |
| 38 | + private final FakeClock clock = new FakeClock(); |
| 39 | + |
| 40 | + @RegisterExtension |
| 41 | + final JpaTestExtensions.JpaIntegrationTestExtension jpa = |
| 42 | + new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension(); |
| 43 | + |
| 44 | + private static final String TMCH_CLAIM_LABEL = "tmch"; |
| 45 | + // RST label found in *.rst.dnl.csv resources. Currently both files are identical |
| 46 | + private static final String RST_CLAIM_LABEL = "test--validate"; |
| 47 | + |
| 48 | + private static final String TMCH_SMD_ID = "tmch"; |
| 49 | + // RST label found in *.rst.smdrl.csv resources. Currently both files are identical |
| 50 | + private static final String RST_SMD_ID = "0000001761385117375880-65535"; |
| 51 | + |
| 52 | + private static final String TMCH_DNL = |
| 53 | + """ |
| 54 | + 1,2024-09-13T02:21:12.0Z |
| 55 | + DNL,lookup-key,insertion-datetime |
| 56 | + LABEL,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z |
| 57 | + """ |
| 58 | + .replace("LABEL", TMCH_CLAIM_LABEL); |
| 59 | + |
| 60 | + private static final String TMCH_SMDRL = |
| 61 | + """ |
| 62 | + 1,2022-11-22T01:49:36.9Z |
| 63 | + smd-id,insertion-datetime |
| 64 | + ID,2013-07-15T00:00:00.0Z |
| 65 | + """ |
| 66 | + .replace("ID", TMCH_SMD_ID); |
| 67 | + |
| 68 | + @BeforeEach |
| 69 | + void setup() throws Exception { |
| 70 | + Splitter lineSplitter = Splitter.on("\n").omitEmptyStrings().trimResults(); |
| 71 | + tm().transact( |
| 72 | + () -> ClaimsListDao.save(ClaimsListParser.parse(lineSplitter.splitToList(TMCH_DNL)))); |
| 73 | + tm().transact( |
| 74 | + () -> |
| 75 | + SignedMarkRevocationListDao.save( |
| 76 | + SmdrlCsvParser.parse(lineSplitter.splitToList(TMCH_SMDRL)))); |
| 77 | + } |
| 78 | + |
| 79 | + @ParameterizedTest |
| 80 | + @MethodSource("provideTestCases") |
| 81 | + @SuppressWarnings("unused") // testCaseName |
| 82 | + void getClaimsList_production(String testCaseName, String tld) { |
| 83 | + var currEnv = RegistryEnvironment.get(); |
| 84 | + try { |
| 85 | + PRODUCTION.setup(); |
| 86 | + var claimsList = ClaimsListDao.get(tld); |
| 87 | + assertThat(claimsList.getClaimKey(TMCH_CLAIM_LABEL)).isPresent(); |
| 88 | + assertThat(claimsList.getClaimKey(RST_CLAIM_LABEL)).isEmpty(); |
| 89 | + } finally { |
| 90 | + currEnv.setup(); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + @ParameterizedTest |
| 95 | + @MethodSource("provideTestCases") |
| 96 | + @SuppressWarnings("unused") // testCaseName |
| 97 | + void getSmdrList_production(String testCaseName, String tld) { |
| 98 | + var currEnv = RegistryEnvironment.get(); |
| 99 | + try { |
| 100 | + PRODUCTION.setup(); |
| 101 | + var smdrl = SignedMarkRevocationList.get(tld); |
| 102 | + assertThat(smdrl.isSmdRevoked(TMCH_SMD_ID, DateTime.now())).isTrue(); |
| 103 | + assertThat(smdrl.isSmdRevoked(RST_SMD_ID, DateTime.now())).isFalse(); |
| 104 | + assertThat(smdrl.size()).isEqualTo(1); |
| 105 | + } finally { |
| 106 | + currEnv.setup(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + @ParameterizedTest |
| 111 | + @MethodSource("provideTestCases") |
| 112 | + @SuppressWarnings("unused") // testCaseName |
| 113 | + void getClaimsList_sandbox(String testCaseName, String tld) { |
| 114 | + var currEnv = RegistryEnvironment.get(); |
| 115 | + try { |
| 116 | + SANDBOX.setup(); |
| 117 | + var claimsList = ClaimsListDao.get(tld); |
| 118 | + if (tld.equals("app")) { |
| 119 | + assertThat(claimsList.getClaimKey(TMCH_CLAIM_LABEL)).isPresent(); |
| 120 | + assertThat(claimsList.getClaimKey(RST_CLAIM_LABEL)).isEmpty(); |
| 121 | + } else { |
| 122 | + assertThat(claimsList.getClaimKey(TMCH_CLAIM_LABEL)).isEmpty(); |
| 123 | + // Currently ote and prod have the same data. |
| 124 | + assertThat(claimsList.getClaimKey(RST_CLAIM_LABEL)).isPresent(); |
| 125 | + } |
| 126 | + } finally { |
| 127 | + currEnv.setup(); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + @ParameterizedTest |
| 132 | + @MethodSource("provideTestCases") |
| 133 | + @SuppressWarnings("unused") // testCaseName |
| 134 | + void getSmdrList_sandbox(String testCaseName, String tld) { |
| 135 | + var currEnv = RegistryEnvironment.get(); |
| 136 | + try { |
| 137 | + SANDBOX.setup(); |
| 138 | + var smdrList = SignedMarkRevocationList.get(tld); |
| 139 | + if (tld.equals("app")) { |
| 140 | + assertThat(smdrList.size()).isEqualTo(1); |
| 141 | + assertThat(smdrList.isSmdRevoked(TMCH_SMD_ID, DateTime.now())).isTrue(); |
| 142 | + assertThat(smdrList.isSmdRevoked(RST_SMD_ID, DateTime.now())).isFalse(); |
| 143 | + } else { |
| 144 | + // Currently ote and prod have the same data. |
| 145 | + assertThat(smdrList.size()).isEqualTo(5); |
| 146 | + assertThat(smdrList.isSmdRevoked(TMCH_SMD_ID, DateTime.now())).isFalse(); |
| 147 | + assertThat(smdrList.isSmdRevoked(RST_SMD_ID, DateTime.now())).isTrue(); |
| 148 | + } |
| 149 | + } finally { |
| 150 | + currEnv.setup(); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + private static Stream<Arguments> provideTestCases() { |
| 155 | + return Stream.of( |
| 156 | + Arguments.of("NotRST", "app"), |
| 157 | + Arguments.of("OTE", "cc-rst-test-tld-1"), |
| 158 | + Arguments.of("PROD", "zz--idn-123")); |
| 159 | + } |
| 160 | +} |
0 commit comments