mirror of
https://github.com/google/nomulus.git
synced 2025-05-05 14:37:52 +02:00
The main goal of this CL is to make the clock constructor injectable (so that tests do not need to use InjectRule to override the clock). The complication is that the clock is used by two static caches (ROOT_CACHE directly and CRL_CACHE indirectly). The clock is not actually used to construct the lock, but rather to verify that the root certificate is within its validity period. For ROOT_CACHE we move the verification to its call sites. This adds a bit overhead because the validity check happens every time the cache is called, not just when the cache is built or refreshed. However this check is rather cheap. Also the resources are included in the jar and the cache is valid for 1 year. Given that we deploy every week, there's not much point making it an expiring cache rather than a static map. For CRL_CACHE we change the key to a tuple of TmchCaMode and X509Certificate. The certificate is no longer provided from the ROOT_CACHE directly and must be verified before it is provided as a cache key. We left the CRL verification inside the cache loader because it (signature verification) is more expensive compared to simple expiration check, and we do not want to do this every time the cache is called. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218385684
65 lines
2.5 KiB
Java
65 lines
2.5 KiB
Java
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.tmch;
|
|
|
|
import static google.registry.testing.TestDataHelper.listFiles;
|
|
import static org.joda.time.DateTimeZone.UTC;
|
|
|
|
import com.google.common.flogger.FluentLogger;
|
|
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
|
|
import google.registry.flows.EppException;
|
|
import google.registry.flows.domain.DomainFlowTmchUtils;
|
|
import google.registry.model.smd.EncodedSignedMark;
|
|
import google.registry.testing.AppEngineRule;
|
|
import google.registry.util.ResourceUtils;
|
|
import google.registry.util.SystemClock;
|
|
import java.nio.file.Path;
|
|
import org.joda.time.DateTime;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
/** Tests that the ICANN testing signed mark files are valid and not expired. */
|
|
@RunWith(JUnit4.class)
|
|
public class TmchTestDataExpirationTest {
|
|
|
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
|
|
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
|
|
|
@Test
|
|
public void testActiveSignedMarkFiles_areValidAndNotExpired() throws Exception {
|
|
DomainFlowTmchUtils tmchUtils =
|
|
new DomainFlowTmchUtils(
|
|
new TmchXmlSignature(
|
|
new TmchCertificateAuthority(TmchCaMode.PILOT, new SystemClock())));
|
|
|
|
for (Path path : listFiles(TmchTestDataExpirationTest.class, "testdata/active/")) {
|
|
if (path.toString().endsWith(".smd")) {
|
|
logger.atInfo().log("Verifying: %s", path);
|
|
String tmchData = ResourceUtils.readResourceUtf8(path.toUri().toURL());
|
|
EncodedSignedMark smd = TmchData.readEncodedSignedMark(tmchData);
|
|
try {
|
|
tmchUtils.verifyEncodedSignedMark(smd, DateTime.now(UTC));
|
|
} catch (EppException e) {
|
|
throw new AssertionError("Error verifying signed mark " + path, e);
|
|
}
|
|
} else {
|
|
logger.atInfo().log("Ignored: %s", path);
|
|
}
|
|
}
|
|
}
|
|
}
|