LCOV - code coverage report
Current view: top level - auth/ldap - FakeLdapGroupBackend.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 10 12 83.3 %
Date: 2022-11-19 15:00:39 Functions: 10 11 90.9 %

          Line data    Source code
       1             : // Copyright (C) 2020 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.auth.ldap;
      16             : 
      17             : import static com.google.gerrit.auth.ldap.Helper.LDAP_UUID;
      18             : 
      19             : import com.google.gerrit.common.Nullable;
      20             : import com.google.gerrit.entities.AccountGroup;
      21             : import com.google.gerrit.entities.GroupDescription;
      22             : import com.google.gerrit.entities.GroupReference;
      23             : import com.google.gerrit.server.CurrentUser;
      24             : import com.google.gerrit.server.account.GroupBackend;
      25             : import com.google.gerrit.server.account.GroupMembership;
      26             : import com.google.gerrit.server.account.ListGroupMembership;
      27             : import com.google.gerrit.server.project.ProjectState;
      28             : import java.util.Collection;
      29             : import java.util.Collections;
      30             : 
      31             : /** Fake Implementation of an LDAP group backend used for testing */
      32             : public class FakeLdapGroupBackend implements GroupBackend {
      33             : 
      34           1 :   FakeLdapGroupBackend() {}
      35             : 
      36             :   @Override
      37             :   public boolean handles(AccountGroup.UUID uuid) {
      38             :     /** Returns true if the provided parameter is an LDAP UUID */
      39           1 :     return uuid.get().startsWith(LDAP_UUID);
      40             :   }
      41             : 
      42             :   @Nullable
      43             :   @Override
      44             :   public GroupDescription.Basic get(AccountGroup.UUID uuid) {
      45           1 :     if (!handles(uuid)) {
      46           0 :       return null;
      47             :     }
      48             : 
      49           1 :     return new GroupDescription.Basic() {
      50             :       @Override
      51             :       public AccountGroup.UUID getGroupUUID() {
      52           1 :         return uuid;
      53             :       }
      54             : 
      55             :       @Override
      56             :       public String getName() {
      57           1 :         return "fake_group";
      58             :       }
      59             : 
      60             :       @Override
      61             :       @Nullable
      62             :       public String getEmailAddress() {
      63           0 :         return null;
      64             :       }
      65             : 
      66             :       @Override
      67             :       @Nullable
      68             :       public String getUrl() {
      69           1 :         return null;
      70             :       }
      71             :     };
      72             :   }
      73             : 
      74             :   @Override
      75             :   public Collection<GroupReference> suggest(String name, ProjectState project) {
      76           1 :     return Collections.emptySet();
      77             :   }
      78             : 
      79             :   @Override
      80             :   public GroupMembership membershipsOf(CurrentUser user) {
      81           1 :     return new ListGroupMembership(Collections.emptyList());
      82             :   }
      83             : 
      84             :   @Override
      85             :   public boolean isVisibleToAll(AccountGroup.UUID uuid) {
      86           1 :     return true;
      87             :   }
      88             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750