mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package rename. The repository is now in a broken state because the code itself hasn't been updated. However this should ensure that git correctly preserves history for each file.
This commit is contained in:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
|
@ -1,107 +0,0 @@
|
|||
// Copyright 2016 The Domain Registry 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 com.google.domain.registry.security;
|
||||
|
||||
import static com.google.domain.registry.security.XsrfTokenManager.X_CSRF_TOKEN;
|
||||
import static com.google.domain.registry.security.XsrfTokenManager.generateToken;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
import com.google.domain.registry.testing.UserInfo;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/** Unit tests for {@link XsrfProtectedServlet}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class XsrfProtectedServletTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withUserService(UserInfo.create("test@example.com", "test@example.com"))
|
||||
.build();
|
||||
|
||||
@Mock
|
||||
HttpServletRequest req;
|
||||
|
||||
@Mock
|
||||
HttpServletResponse rsp;
|
||||
|
||||
XsrfProtectedServlet servlet = new XsrfProtectedServlet("foo", false) {
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse rsp) {
|
||||
rsp.setStatus(SC_OK);
|
||||
}};
|
||||
|
||||
String validXsrfToken;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.validXsrfToken = generateToken("foo");
|
||||
}
|
||||
|
||||
private void setup(String xsrf, String method) throws Exception {
|
||||
when(req.getHeader(X_CSRF_TOKEN)).thenReturn(xsrf);
|
||||
when(req.getMethod()).thenReturn(method);
|
||||
when(req.getServletPath()).thenReturn("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess() throws Exception {
|
||||
setup(validXsrfToken, "post");
|
||||
servlet.service(req, rsp);
|
||||
verify(rsp).setStatus(SC_OK);
|
||||
}
|
||||
|
||||
private void doInvalidRequestTest(String xsrf) throws Exception {
|
||||
setup(xsrf, "post");
|
||||
servlet.service(req, rsp);
|
||||
verify(rsp).sendError(eq(SC_FORBIDDEN), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badXsrfToken() throws Exception {
|
||||
doInvalidRequestTest("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingXsrfToken() throws Exception {
|
||||
doInvalidRequestTest(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_notAdmin() throws Exception {
|
||||
setup(validXsrfToken, "post");
|
||||
new XsrfProtectedServlet("foo", true) {
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse rsp) {
|
||||
rsp.setStatus(SC_OK);
|
||||
}}.service(req, rsp);
|
||||
verify(rsp).sendError(eq(SC_FORBIDDEN), anyString());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue