mirror of
https://github.com/google/nomulus.git
synced 2025-05-02 13:07:50 +02:00
116 lines
4.1 KiB
Java
116 lines
4.1 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.dns;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
import static google.registry.testing.DatastoreHelper.createTld;
|
|
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
|
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
|
import static google.registry.testing.DatastoreHelper.persistActiveSubordinateHost;
|
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
|
import static google.registry.testing.JUnitBackports.expectThrows;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
|
|
import google.registry.dns.DnsConstants.TargetType;
|
|
import google.registry.model.domain.DomainResource;
|
|
import google.registry.request.HttpException.BadRequestException;
|
|
import google.registry.request.HttpException.NotFoundException;
|
|
import google.registry.testing.AppEngineRule;
|
|
import google.registry.testing.FakeClock;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
/** Unit tests for {@link RefreshDnsAction}. */
|
|
@RunWith(JUnit4.class)
|
|
public class RefreshDnsActionTest {
|
|
|
|
@Rule
|
|
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
.withDatastore()
|
|
.withTaskQueue()
|
|
.build();
|
|
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
|
private final FakeClock clock = new FakeClock();
|
|
|
|
private void run(TargetType type, String name) {
|
|
RefreshDnsAction action = new RefreshDnsAction();
|
|
action.clock = clock;
|
|
action.domainOrHostName = name;
|
|
action.type = type;
|
|
action.dnsQueue = dnsQueue;
|
|
action.run();
|
|
}
|
|
|
|
@Before
|
|
public void before() {
|
|
createTld("xn--q9jyb4c");
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_host() throws Exception {
|
|
DomainResource domain = persistActiveDomain("example.xn--q9jyb4c");
|
|
persistActiveSubordinateHost("ns1.example.xn--q9jyb4c", domain);
|
|
run(TargetType.HOST, "ns1.example.xn--q9jyb4c");
|
|
verify(dnsQueue).addHostRefreshTask("ns1.example.xn--q9jyb4c");
|
|
verifyNoMoreInteractions(dnsQueue);
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_externalHostNotEnqueued() throws Exception {
|
|
persistActiveDomain("example.xn--q9jyb4c");
|
|
persistActiveHost("ns1.example.xn--q9jyb4c");
|
|
BadRequestException thrown =
|
|
expectThrows(
|
|
BadRequestException.class,
|
|
() -> {
|
|
try {
|
|
run(TargetType.HOST, "ns1.example.xn--q9jyb4c");
|
|
} finally {
|
|
verifyNoMoreInteractions(dnsQueue);
|
|
}
|
|
});
|
|
assertThat(thrown)
|
|
.hasMessageThat()
|
|
.contains("ns1.example.xn--q9jyb4c isn't a subordinate hostname");
|
|
}
|
|
|
|
@Test
|
|
public void testSuccess_domain() throws Exception {
|
|
persistActiveDomain("example.xn--q9jyb4c");
|
|
run(TargetType.DOMAIN, "example.xn--q9jyb4c");
|
|
verify(dnsQueue).addDomainRefreshTask("example.xn--q9jyb4c");
|
|
verifyNoMoreInteractions(dnsQueue);
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_unqualifiedName() throws Exception {
|
|
assertThrows(BadRequestException.class, () -> run(TargetType.DOMAIN, "example"));
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_hostDoesNotExist() throws Exception {
|
|
assertThrows(NotFoundException.class, () -> run(TargetType.HOST, "ns1.example.xn--q9jyb4c"));
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_domainDoesNotExist() throws Exception {
|
|
assertThrows(NotFoundException.class, () -> run(TargetType.DOMAIN, "example.xn--q9jyb4c"));
|
|
}
|
|
}
|