-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
cosec-api/src/test/kotlin/me/ahoo/cosec/api/context/SecurityContextTest.kt
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,52 @@ | ||
/* | ||
* Copyright [2021-present] [ahoo wang <[email protected]> (https://github.com/Ahoo-Wang)]. | ||
* 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 me.ahoo.cosec.api.context | ||
|
||
import me.ahoo.cosec.api.principal.CoSecPrincipal | ||
import me.ahoo.cosec.api.tenant.Tenant | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.* | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class SecurityContextTest { | ||
@Test | ||
fun getRequiredAttribute() { | ||
val securityContext: SecurityContext = object : SecurityContext { | ||
override val principal: CoSecPrincipal | ||
get() = TODO("Not yet implemented") | ||
|
||
override fun setAttribute(key: String, value: Any): SecurityContext { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun <T> getAttribute(key: String): T? { | ||
if (key == "no") { | ||
return null | ||
} | ||
return key as T | ||
} | ||
|
||
override val tenant: Tenant | ||
get() = TODO("Not yet implemented") | ||
} | ||
assertThat(securityContext.getAttribute("key"), equalTo("key")) | ||
assertThat(securityContext.getRequiredAttribute("key"), equalTo("key")) | ||
|
||
assertThat(securityContext.getAttribute("no"), nullValue()) | ||
Assertions.assertThrows(IllegalArgumentException::class.java) { | ||
securityContext.getRequiredAttribute("no") | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
cosec-api/src/test/kotlin/me/ahoo/cosec/api/principal/CoSecPrincipalTest.kt
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,62 @@ | ||
/* | ||
* Copyright [2021-present] [ahoo wang <[email protected]> (https://github.com/Ahoo-Wang)]. | ||
* 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 me.ahoo.cosec.api.principal | ||
|
||
import me.ahoo.cosec.api.principal.CoSecPrincipal.Companion.ANONYMOUS_ID | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
|
||
class CoSecPrincipalTest { | ||
|
||
@Test | ||
fun anonymous() { | ||
val anonymous = object : CoSecPrincipal { | ||
override val id: String | ||
get() = ANONYMOUS_ID | ||
|
||
override fun getName(): String { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override val attrs: Map<String, Any> | ||
get() = TODO("Not yet implemented") | ||
override val policies: Set<String> | ||
get() = TODO("Not yet implemented") | ||
override val roles: Set<String> | ||
get() = TODO("Not yet implemented") | ||
} | ||
assertThat(anonymous.anonymous(), equalTo(true)) | ||
} | ||
|
||
@Test | ||
fun authenticated() { | ||
val authenticated = object : CoSecPrincipal { | ||
override val id: String | ||
get() = "id" | ||
|
||
override fun getName(): String { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override val attrs: Map<String, Any> | ||
get() = TODO("Not yet implemented") | ||
override val policies: Set<String> | ||
get() = TODO("Not yet implemented") | ||
override val roles: Set<String> | ||
get() = TODO("Not yet implemented") | ||
} | ||
assertThat(authenticated.authenticated(), equalTo(true)) | ||
} | ||
} |
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
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
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
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
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
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
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
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