import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+import javax.annotation.Nullable;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.sonar.auth.gitlab.GsonGroup;
import org.sonar.auth.gitlab.GsonProjectMember;
import org.sonar.auth.gitlab.GsonUser;
+import org.sonar.auth.gitlab.GsonMemberRole;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@Rule
public LogTester logTester = new LogTester();
- private GitlabPaginatedHttpClient gitlabPaginatedHttpClient = mock();
+ private final GitlabPaginatedHttpClient gitlabPaginatedHttpClient = mock();
private final MockWebServer server = new MockWebServer();
private GitlabApplicationClient underTest;
public void getAllProjectMembers_whenCallIsInError_rethrows() {
String token = "token-toto";
GitlabToken gitlabToken = new GitlabToken(token);
- List<GsonProjectMember> expectedProjectMembers = expectedProjectMembers();
when(gitlabPaginatedHttpClient.get(eq(gitlabUrl), eq(gitlabToken), eq("/projects/42/members/all"), any())).thenThrow(new IllegalStateException("exception"));
assertThatIllegalStateException()
}
private static List<GsonProjectMember> expectedProjectMembers() {
- GsonProjectMember user1 = createGsonProjectMember(12818153, 5);
- GsonProjectMember user2 = createGsonProjectMember(22330087, 50);
- return List.of(user1, user2);
+ GsonProjectMember user1 = createGsonProjectMember(12818153, 5, null);
+ GsonProjectMember user2 = createGsonProjectMember(22330087, 50, null);
+ GsonProjectMember user3 = createGsonProjectMember(20824381, 40, new GsonMemberRole("custom-role"));
+ return List.of(user1, user2, user3);
}
- private static GsonProjectMember createGsonProjectMember(int id, int accessLevel) {
- return new GsonProjectMember(id, accessLevel);
+ private static GsonProjectMember createGsonProjectMember(int id, int accessLevel, @Nullable GsonMemberRole gsonMemberRole) {
+ return new GsonProjectMember(id, accessLevel, gsonMemberRole);
}
private static String getResponseContent(String path) throws IOException {
"created_at": "2024-08-05T14:38:37.647Z",
"expires_at": "2024-09-04",
"membership_state": "active"
+ },
+ {
+ "id": 20824381,
+ "username": "nolwenncadic",
+ "name": "Nolwenn Cadic",
+ "state": "active",
+ "locked": false,
+ "avatar_url": "https://secure.gravatar.com/avatar/7c80cccd6d4e547a2681964e8950228d6c97b9b755f2c348516b80da10d4140d?s=80&d=identicon",
+ "web_url": "https://gitlab.com/nolwenncadic",
+ "access_level": 40,
+ "created_at": "2024-08-26T14:42:45.013Z",
+ "created_by": {
+ "id": 14799915,
+ "username": "Nolwenn-cadic-sonarsource",
+ "name": "Nolwenn Cadic",
+ "state": "active",
+ "locked": false,
+ "avatar_url": "https://secure.gravatar.com/avatar/3b2216084856683e6e25bb55b824af42fb5ec5da97cd524e17599023a1e64adc?s=80&d=identicon",
+ "web_url": "https://gitlab.com/Nolwenn-cadic-sonarsource"
+ },
+ "expires_at": null,
+ "membership_state": "active",
+ "member_role": {
+ "id": 1002974,
+ "group_id": 6164984,
+ "name": "custom-role",
+ "description": "custom role",
+ "base_access_level": 40,
+ "admin_cicd_variables": false,
+ "admin_compliance_framework": false,
+ "admin_group_member": false,
+ "admin_integrations": false,
+ "admin_merge_request": false,
+ "admin_push_rules": false,
+ "admin_runners": false,
+ "admin_terraform_state": false,
+ "admin_vulnerability": false,
+ "admin_web_hook": false,
+ "archive_project": false,
+ "manage_deploy_tokens": false,
+ "manage_group_access_tokens": false,
+ "manage_merge_request_settings": false,
+ "manage_project_access_tokens": false,
+ "manage_security_policy_link": false,
+ "read_code": true,
+ "read_crm_contact": false,
+ "read_dependency": false,
+ "read_runners": false,
+ "read_vulnerability": false,
+ "remove_group": false,
+ "remove_project": false
+ }
}
]
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.auth.gitlab;
+
+import com.google.gson.annotations.SerializedName;
+
+public record GsonMemberRole(@SerializedName("name") String name) {
+}
package org.sonar.auth.gitlab;
import com.google.gson.annotations.SerializedName;
+import javax.annotation.Nullable;
public record GsonProjectMember (
@SerializedName("id")
long id,
@SerializedName("access_level")
- int accessLevel
+ int accessLevel,
+ @SerializedName("member_role")
+ @Nullable
+ GsonMemberRole gsonMemberRole
){
}