-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added /acls endpoint to get all the ACLs (#231)
* Adding /acls endpoint to get all the ACLs * Adding unit tests Co-authored-by: Alexis Souquiere <[email protected]>
- Loading branch information
1 parent
004ed68
commit 1fd60f8
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...trollers/AccessControlListController.java → ...lers/acl/AccessControlListController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../java/com/michelin/ns4kafka/controllers/acl/AccessControlListNonNamespacedController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.michelin.ns4kafka.controllers.acl; | ||
|
||
import com.michelin.ns4kafka.controllers.generic.NonNamespacedResourceController; | ||
import com.michelin.ns4kafka.models.AccessControlEntry; | ||
import com.michelin.ns4kafka.security.ResourceBasedSecurityRule; | ||
import com.michelin.ns4kafka.services.AccessControlEntryService; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
import javax.annotation.security.RolesAllowed; | ||
import javax.inject.Inject; | ||
import java.util.List; | ||
|
||
@Tag(name = "ACLs resource") | ||
@Controller("/api/acls") | ||
@RolesAllowed(ResourceBasedSecurityRule.IS_ADMIN) | ||
public class AccessControlListNonNamespacedController extends NonNamespacedResourceController { | ||
|
||
/** | ||
* The ACL service | ||
*/ | ||
@Inject | ||
AccessControlEntryService accessControlEntryService; | ||
|
||
/** | ||
* Get all the ACLs of all namespaces | ||
* @return A list of ACLs | ||
*/ | ||
@Get | ||
public List<AccessControlEntry> listAll() { | ||
return accessControlEntryService.findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/test/java/com/michelin/ns4kafka/controllers/AccessControlListControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../java/com/michelin/ns4kafka/controllers/AccessControlListNonNamespacedControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.michelin.ns4kafka.controllers; | ||
|
||
import com.michelin.ns4kafka.controllers.acl.AccessControlListNonNamespacedController; | ||
import com.michelin.ns4kafka.models.AccessControlEntry; | ||
import com.michelin.ns4kafka.models.Namespace; | ||
import com.michelin.ns4kafka.models.ObjectMeta; | ||
import com.michelin.ns4kafka.services.AccessControlEntryService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AccessControlListNonNamespacedControllerTest { | ||
/** | ||
* The mocked ACL service | ||
*/ | ||
@Mock | ||
AccessControlEntryService accessControlEntryService; | ||
|
||
/** | ||
* The mocked ACL controller | ||
*/ | ||
@InjectMocks | ||
AccessControlListNonNamespacedController accessControlListNonNamespacedController; | ||
|
||
@Test | ||
void listAll() { | ||
AccessControlEntry ace1 = AccessControlEntry.builder() | ||
.metadata(ObjectMeta.builder().namespace("namespace1").build()) | ||
.spec(AccessControlEntry.AccessControlEntrySpec.builder().grantedTo("namespace1").build()).build(); | ||
AccessControlEntry ace2 = AccessControlEntry.builder() | ||
.metadata(ObjectMeta.builder().namespace("namespace2").build()) | ||
.spec(AccessControlEntry.AccessControlEntrySpec.builder().grantedTo("namespace2").build()).build(); | ||
|
||
when(accessControlEntryService.findAll()).thenReturn(List.of(ace1, ace2)); | ||
|
||
List<AccessControlEntry> actual = accessControlListNonNamespacedController.listAll(); | ||
Assertions.assertEquals(2, actual.size()); | ||
Assertions.assertEquals(List.of(ace1, ace2), actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters