]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10134 show now fails when using id and different organization
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 7 Dec 2017 14:38:42 +0000 (15:38 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 14 Dec 2017 16:03:35 +0000 (17:03 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java

index ea9685620134d6f0b92567c8fe47c20c9b7d3d01..b6a08d62f456d015dbb84873c5b99fc30daca374 100644 (file)
@@ -105,7 +105,7 @@ public class ShowAction implements QualityGatesWsAction {
       return checkFound(dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name), "No quality gate has been found for name %s", name);
     }
     if (id != null) {
-      return qualityGateFinder.getById(dbSession, id);
+      return qualityGateFinder.getByOrganizationAndId(dbSession, organization, id);
     }
     throw new IllegalArgumentException("No parameter has been set to identify a quality gate");
   }
index beff812603e9ebeb8b3c88f1ce6b555cd4b7ea90..d5ee72e1cd172f2289a2b498a9fdc01f26c3f6e8 100644 (file)
@@ -347,4 +347,34 @@ public class ShowActionTest {
       .setParam("organization", "Unknown")
       .execute();
   }
+
+  @Test
+  public void fail_when_quality_gate_belongs_to_another_organization() {
+    OrganizationDto organization = db.organizations().insert();
+    OrganizationDto otherOrganization = db.organizations().insert();
+    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
+
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage(format("No quality gate has been found for name %s", qualityGate.getName()));
+
+    ws.newRequest()
+      .setParam("name", qualityGate.getName())
+      .setParam("organization", organization.getKey())
+      .execute();
+  }
+
+  @Test
+  public void fail_when_quality_gate_belongs_to_another_organization_using_id_parameter() {
+    OrganizationDto organization = db.organizations().insert();
+    OrganizationDto otherOrganization = db.organizations().insert();
+    QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
+
+    expectedException.expect(NotFoundException.class);
+    expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getId(), organization.getName()));
+
+    ws.newRequest()
+      .setParam("id", qualityGate.getId().toString())
+      .setParam("organization", organization.getKey())
+      .execute();
+  }
 }