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
62 lines
2.4 KiB
Java
62 lines
2.4 KiB
Java
// Copyright 2017 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 javax.servlet.http.HttpServletResponse.SC_OK;
|
|
import static org.mockito.Matchers.any;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import com.google.appengine.api.urlfetch.HTTPRequest;
|
|
import com.google.appengine.api.urlfetch.HTTPResponse;
|
|
import com.google.appengine.api.urlfetch.URLFetchService;
|
|
import google.registry.testing.AppEngineRule;
|
|
import google.registry.testing.BouncyCastleProviderRule;
|
|
import google.registry.testing.FakeClock;
|
|
import google.registry.testing.MockitoJUnitRule;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
import org.mockito.ArgumentCaptor;
|
|
import org.mockito.Captor;
|
|
import org.mockito.Mock;
|
|
|
|
/** Common code for unit tests of classes that extend {@link Marksdb}. */
|
|
@RunWith(JUnit4.class)
|
|
public class TmchActionTestCase {
|
|
|
|
static final String MARKSDB_LOGIN = "lolcat:attack";
|
|
static final String MARKSDB_URL = "http://127.0.0.1/love";
|
|
|
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
|
@Rule public final MockitoJUnitRule mocks = MockitoJUnitRule.create();
|
|
@Rule public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
|
|
|
|
@Mock URLFetchService fetchService;
|
|
@Mock HTTPResponse httpResponse;
|
|
@Captor ArgumentCaptor<HTTPRequest> httpRequest;
|
|
|
|
final FakeClock clock = new FakeClock();
|
|
final Marksdb marksdb = new Marksdb();
|
|
|
|
@Before
|
|
public void commonBefore() throws Exception {
|
|
marksdb.fetchService = fetchService;
|
|
marksdb.tmchMarksdbUrl = MARKSDB_URL;
|
|
marksdb.marksdbPublicKey = TmchData.loadPublicKey(TmchTestData.loadBytes("pubkey"));
|
|
when(fetchService.fetch(any(HTTPRequest.class))).thenReturn(httpResponse);
|
|
when(httpResponse.getResponseCode()).thenReturn(SC_OK);
|
|
}
|
|
}
|