// Path: endpoints-control/src/main/java/com/google/api/control/model/MethodRegistry.java
// public static final class AuthInfo {
//   private final Map<String, Set<String>> providerIdsToAudiences;
// 
//   public AuthInfo(Map<String, Set<String>> providerIdsToAudiences) {
//     Preconditions.checkNotNull(providerIdsToAudiences);
//     this.providerIdsToAudiences = providerIdsToAudiences;
//   }
// 
//   public boolean isProviderIdAllowed(String providerid) {
//     Preconditions.checkNotNull(providerid);
//     return this.providerIdsToAudiences.containsKey(providerid);
//   }
// 
//   public Set<String> getAudiencesForProvider(String providerId) {
//     Preconditions.checkNotNull(providerId);
// 
//     if (this.providerIdsToAudiences.containsKey(providerId)) {
//       return this.providerIdsToAudiences.get(providerId);
//     }
//     return ImmutableSet.<String>of();
//   }
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.api.AuthProvider;
import com.google.api.Authentication;
import com.google.api.client.util.Clock;
import com.google.api.control.model.MethodRegistry.AuthInfo;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
import org.jose4j.jwt.JwtClaims;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
/*
 * Copyright 2016 Google Inc. 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.api.auth;






/**
 * Tests for {@link Authenticator}.
 *
 * @author yangguan@google.com
 *
 */
public class AuthenticatorTest {
  private static final List<String> AUDIENCES = ImmutableList.of("aud1", "aud2");
  private static final String AUTH_TOKEN = "auth-token";
  private static final String EMAIL = "email@test.com";
  private static final int EXPIRATION_IN_FUTURE = 5;
  private static final String ID = "id";
  private static final String ISSUER = "issuer";
  private static final String PROVIDER_ID = "provider-id";
  private static final int NOT_BEFORE_IN_PAST = 0;
  private static final String SERVICE_NAME = "service-name";

  private final Map<String, String> issuersToProviderIds =
      ImmutableMap.<String, String>of(ISSUER, PROVIDER_ID);
  private final AuthTokenDecoder authTokenDecoder = mock(AuthTokenDecoder.class);
  private final Authenticator authenticator =
      new Authenticator(authTokenDecoder, Clock.SYSTEM, issuersToProviderIds);

  private final HttpServletRequest request = mock(HttpServletRequest.class);
  private final JwtClaims jwtClaims =
      createJwtClaims(AUDIENCES, EMAIL, EXPIRATION_IN_FUTURE, ID, NOT_BEFORE_IN_PAST, ISSUER);
  private final UserInfo userInfo = new UserInfo(AUDIENCES, EMAIL, ID, ISSUER);

  @Before
  public void setUp() {
    when(authTokenDecoder.decode(AUTH_TOKEN)).thenReturn(jwtClaims);
    when(request.getHeader(HttpHeaders.AUTHORIZATION)).thenReturn("Bearer " + AUTH_TOKEN);
  }

  @Test
  public void testAuthenticate() {
// Path: endpoints-control/src/main/java/com/google/api/control/model/MethodRegistry.java
// public static final class AuthInfo {
//   private final Map<String, Set<String>> providerIdsToAudiences;
// 
//   public AuthInfo(Map<String, Set<String>> providerIdsToAudiences) {
//     Preconditions.checkNotNull(providerIdsToAudiences);
//     this.providerIdsToAudiences = providerIdsToAudiences;
//   }
// 
//   public boolean isProviderIdAllowed(String providerid) {
//     Preconditions.checkNotNull(providerid);
//     return this.providerIdsToAudiences.containsKey(providerid);
//   }
// 
//   public Set<String> getAudiencesForProvider(String providerId) {
//     Preconditions.checkNotNull(providerId);
// 
//     if (this.providerIdsToAudiences.containsKey(providerId)) {
//       return this.providerIdsToAudiences.get(providerId);
//     }
//     return ImmutableSet.<String>of();
//   }
// }


// Path: endpoints-auth/src/test/java/com/google/api/auth/AuthenticatorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.api.AuthProvider;
import com.google.api.Authentication;
import com.google.api.client.util.Clock;
import com.google.api.control.model.MethodRegistry.AuthInfo;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders;
import org.jose4j.jwt.JwtClaims;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;

/*
 * Copyright 2016 Google Inc. 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.api.auth;






/**
 * Tests for {@link Authenticator}.
 *
 * @author yangguan@google.com
 *
 */
public class AuthenticatorTest {
  private static final List<String> AUDIENCES = ImmutableList.of("aud1", "aud2");
  private static final String AUTH_TOKEN = "auth-token";
  private static final String EMAIL = "email@test.com";
  private static final int EXPIRATION_IN_FUTURE = 5;
  private static final String ID = "id";
  private static final String ISSUER = "issuer";
  private static final String PROVIDER_ID = "provider-id";
  private static final int NOT_BEFORE_IN_PAST = 0;
  private static final String SERVICE_NAME = "service-name";

  private final Map<String, String> issuersToProviderIds =
      ImmutableMap.<String, String>of(ISSUER, PROVIDER_ID);
  private final AuthTokenDecoder authTokenDecoder = mock(AuthTokenDecoder.class);
  private final Authenticator authenticator =
      new Authenticator(authTokenDecoder, Clock.SYSTEM, issuersToProviderIds);

  private final HttpServletRequest request = mock(HttpServletRequest.class);
  private final JwtClaims jwtClaims =
      createJwtClaims(AUDIENCES, EMAIL, EXPIRATION_IN_FUTURE, ID, NOT_BEFORE_IN_PAST, ISSUER);
  private final UserInfo userInfo = new UserInfo(AUDIENCES, EMAIL, ID, ISSUER);

  @Before
  public void setUp() {
    when(authTokenDecoder.decode(AUTH_TOKEN)).thenReturn(jwtClaims);
    when(request.getHeader(HttpHeaders.AUTHORIZATION)).thenReturn("Bearer " + AUTH_TOKEN);
  }

  @Test
  public void testAuthenticate() {
    AuthInfo authInfo =