Browse Source

tests for webfinger url normalization.

pull/477/head
William Kim 11 years ago
parent
commit
809a243b64
  1. 74
      openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestWebfingerIssuerService.java
  2. 210
      openid-connect-common/src/test/java/org/mitre/discovery/util/TestWebfingerURLNormalizer.java

74
openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestWebfingerIssuerService.java

@ -1,74 +0,0 @@
/*******************************************************************************
* Copyright 2013 The MITRE Corporation
* and the MIT Kerberos and Internet Trust Consortium
*
* 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 org.mitre.openid.connect.client.service.impl;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.BasicConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mitre.openid.connect.client.model.IssuerServiceResponse;
import org.mockito.Mockito;
/**
* @author wkim
*
*/
public class TestWebfingerIssuerService {
// Test fixture:
private HttpServletRequest request;
// WebfingerIssuerService.parameterName = "identifier";
private String identifier = "user@example.org";
private String loginPageUrl = "https://www.example.com/account";
private WebfingerIssuerService service = new WebfingerIssuerService();
@Before
public void prepare() {
BasicConfigurator.configure();
service.setLoginPageUrl(loginPageUrl);
request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getParameter("identifier")).thenReturn(identifier);
}
@After
public void cleanup() {
BasicConfigurator.resetConfiguration();
}
//@Test
public void getIssuer_validIdentifier() {
IssuerServiceResponse response = service.getIssuer(request);
String expectedIssuer = "https://example.org/.well-known/webfinger";
assertThat(response.getIssuer(), equalTo(expectedIssuer));
}
}

210
openid-connect-common/src/test/java/org/mitre/discovery/util/TestWebfingerURLNormalizer.java

@ -0,0 +1,210 @@
/*******************************************************************************
* Copyright 2013 The MITRE Corporation
* and the MIT Kerberos and Internet Trust Consortium
*
* 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 org.mitre.discovery.util;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import com.google.common.collect.Lists;
/**
* @author wkim
*
*/
public class TestWebfingerURLNormalizer {
// Test fixture:
private String parameterName = "identifier";
private List<String> inputIndentifierList = Lists.newArrayList(
"example.com",
"example.com:8080",
"example.com/path",
"example.com?query",
"example.com#fragment",
"example.com:8080/path?query#fragment",
"http://example.com",
"http://example.com:8080",
"http://example.com/path",
"http://example.com?query",
"http://example.com#fragment",
"http://example.com:8080/path?query#fragment",
"nov@example.com",
"nov@example.com:8080",
"nov@example.com/path",
"nov@example.com?query",
"nov@example.com#fragment",
"nov@example.com:8080/path?query#fragment",
"acct:nov@matake.jp",
"acct:nov@example.com:8080",
"acct:nov@example.com/path",
"acct:nov@example.com?query",
"acct:nov@example.com#fragment",
"acct:nov@example.com:8080/path?query#fragment",
"mailto:nov@matake.jp",
"mailto:nov@example.com:8080",
"mailto:nov@example.com/path",
"mailto:nov@example.com?query",
"mailto:nov@example.com#fragment",
"mailto:nov@example.com:8080/path?query#fragment",
"localhost",
"localhost:8080",
"localhost/path",
"localhost?query",
"localhost#fragment",
"localhost/path?query#fragment",
"nov@localhost",
"nov@localhost:8080",
"nov@localhost/path",
"nov@localhost?query",
"nov@localhost#fragmentx",
"nov@localhost/path?query#fragment",
"tel:+810312345678",
"device:192.168.2.1",
"device:192.168.2.1:8080",
"device:192.168.2.1/path",
"device:192.168.2.1?query",
"device:192.168.2.1#fragment",
"device:192.168.2.1/path?query#fragment");
private List<String> expectedNormalizedIssuerList = Lists.newArrayList(
"https://example.com",
"https://example.com:8080",
"https://example.com/path",
"https://example.com?query",
"https://example.com",
"https://example.com:8080/path?query",
"http://example.com",
"http://example.com:8080",
"http://example.com/path",
"http://example.com?query",
"http://example.com",
"http://example.com:8080/path?query",
"acct:nov@example.com",
"https://nov@example.com:8080",
"https://nov@example.com/path",
"https://nov@example.com?query",
"acct:nov@example.com",
"https://nov@example.com:8080/path?query",
"acct:nov@matake.jp",
"acct:nov@example.com:8080",
"acct:nov@example.com/path",
"acct:nov@example.com?query",
"acct:nov@example.com",
"acct:nov@example.com:8080/path?query",
"mailto:nov@matake.jp",
"mailto:nov@example.com:8080",
"mailto:nov@example.com/path",
"mailto:nov@example.com?query",
"mailto:nov@example.com",
"mailto:nov@example.com:8080/path?query",
"https://localhost",
"https://localhost:8080",
"https://localhost/path",
"https://localhost?query",
"https://localhost",
"https://localhost/path?query",
"acct:nov@localhost",
"https://nov@localhost:8080",
"https://nov@localhost/path",
"https://nov@localhost?query",
"https://nov@localhost?query",
"https://nov@localhost/path?query",
"tel:+810312345678",
"device:192.168.2.1",
"device:192.168.2.1:8080",
"device:192.168.2.1/path",
"device:192.168.2.1?query",
"device:192.168.2.1",
"device:192.168.2.1/path?query");
/*
Adapted from Nov Matake's Ruby normalizer implementation.
## INPUT => NORMALIZED
# example.com => https://example.com
# example.com:8080 => https://example.com:8080
# example.com/path => https://example.com/path
# example.com?query => https://example.com?query
# example.com#fragment => https://example.com
# example.com:8080/path?query#fragment => https://example.com:8080/path?query
# http://example.com => http://example.com
# http://example.com:8080 => http://example.com:8080
# http://example.com/path => http://example.com/path
# http://example.com?query => http://example.com?query
# http://example.com#fragment => http://example.com
# http://example.com:8080/path?query#fragment => http://example.com:8080/path?query
# nov@example.com => acct:nov@example.com
# nov@example.com:8080 => https://nov@example.com:8080
# nov@example.com/path => https://nov@example.com/path
# nov@example.com?query => https://nov@example.com?query
# nov@example.com#fragment => acct:nov@example.com
# nov@example.com:8080/path?query#fragment => https://nov@example.com:8080/path?query
# acct:nov@matake.jp => acct:nov@matake.jp
# acct:nov@example.com:8080 => acct:nov@example.com:8080
# acct:nov@example.com/path => acct:nov@example.com/path
# acct:nov@example.com?query => acct:nov@example.com?query
# acct:nov@example.com#fragment => acct:nov@example.com
# acct:nov@example.com:8080/path?query#fragment => acct:nov@example.com:8080/path?query
# mailto:nov@matake.jp => mailto:nov@matake.jp
# mailto:nov@example.com:8080 => mailto:nov@example.com:8080
# mailto:nov@example.com/path => mailto:nov@example.com/path
# mailto:nov@example.com?query => mailto:nov@example.com?query
# mailto:nov@example.com#fragment => mailto:nov@example.com
# mailto:nov@example.com:8080/path?query#fragment => mailto:nov@example.com:8080/path?query
# localhost => https://localhost
# localhost:8080 => https://localhost:8080
# localhost/path => https://localhost/path
# localhost?query => https://localhost?query
# localhost#fragment => https://localhost
# localhost/path?query#fragment => https://localhost/path?query
# nov@localhost => acct:nov@localhost
# nov@localhost:8080 => https://nov@localhost:8080
# nov@localhost/path => https://nov@localhost/path
# nov@localhost?query => https://nov@localhost?query
# nov@localhost#fragment => acct:nov@localhost
# nov@localhost/path?query#fragment => https://nov@localhost/path?query
# tel:+810312345678 => tel:+810312345678
# device:192.168.2.1 => device:192.168.2.1
# device:192.168.2.1:8080 => device:192.168.2.1:8080
# device:192.168.2.1/path => device:192.168.2.1/path
# device:192.168.2.1?query => device:192.168.2.1?query
# device:192.168.2.1#fragment => device:192.168.2.1
# device:192.168.2.1/path?query#fragment => device:192.168.2.1/path?query
*/
@Test
public void normalizeResource() {
for (int i = 0; i < inputIndentifierList.size(); i++) {
String identifier = inputIndentifierList.get(i);
String expectedIssuer = expectedNormalizedIssuerList.get(i);
String actualIssuer = WebfingerURLNormalizer.normalizeResource(identifier).toUriString();
assertEquals("Identifer/Issuer pair #" + i + " failed.", expectedIssuer, actualIssuer);
}
}
}
Loading…
Cancel
Save