-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test : Context tests for auto configurations
- Loading branch information
Showing
6 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresContextTest.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,29 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 io.wwan13.wintersecurity.context.allconfigures; | ||
|
||
import io.wwan13.wintersecurity.ContextTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Import(AllConfiguresTestConfigure.class) | ||
public class AllConfiguresContextTest extends ContextTest { | ||
|
||
@Test | ||
void contextLoad() { | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/test/java/io/wwan13/wintersecurity/context/allconfigures/AllConfiguresTestConfigure.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,66 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 io.wwan13.wintersecurity.context.allconfigures; | ||
|
||
import io.wwan13.wintersecurity.auth.authorizedrequest.support.AuthorizedRequestRegistry; | ||
import io.wwan13.wintersecurity.config.EnableJwtProvider; | ||
import io.wwan13.wintersecurity.config.EnableSecureRequest; | ||
import io.wwan13.wintersecurity.config.JwtProviderConfigurer; | ||
import io.wwan13.wintersecurity.config.SecureRequestConfigurer; | ||
import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; | ||
import io.wwan13.wintersecurity.resolve.RequestUserId; | ||
import io.wwan13.wintersecurity.resolve.RequestUserRoles; | ||
import io.wwan13.wintersecurity.resolve.support.TargetAnnotationsRegistry; | ||
import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
|
||
@TestConfiguration | ||
@EnableJwtProvider | ||
@EnableSecureRequest | ||
public class AllConfiguresTestConfigure | ||
implements JwtProviderConfigurer, SecureRequestConfigurer { | ||
|
||
@Override | ||
public void configureJwt(JwtPropertiesRegistry registry) { | ||
registry | ||
.accessTokenValidity(100000000000L) | ||
.refreshTokenValidity(100000000000L); | ||
} | ||
|
||
@Override | ||
public void configureSecretKey(SecretKeyRegistry registry) { | ||
registry | ||
.secretKey("asdfghjklqwertyuiopzxcvbnmasddfgwerasf"); | ||
} | ||
|
||
@Override | ||
public void registerAuthPatterns(AuthorizedRequestRegistry registry) { | ||
registry | ||
.uriPatterns("/api/test/**") | ||
.allHttpMethods() | ||
.permitAll() | ||
|
||
.elseRequestAuthenticated(); | ||
} | ||
|
||
@Override | ||
public void registerTargetAnnotations(TargetAnnotationsRegistry registry) { | ||
registry | ||
.addSubjectResolveAnnotation(RequestUserId.class) | ||
.addRolesResolveAnnotation(RequestUserRoles.class); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderContextTest.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,29 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 io.wwan13.wintersecurity.context.jwtprovider; | ||
|
||
import io.wwan13.wintersecurity.ContextTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Import(JwtProviderTestConfig.class) | ||
public class JwtProviderContextTest extends ContextTest { | ||
|
||
@Test | ||
void contextLoad() { | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/io/wwan13/wintersecurity/context/jwtprovider/JwtProviderTestConfig.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,41 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 io.wwan13.wintersecurity.context.jwtprovider; | ||
|
||
import io.wwan13.wintersecurity.config.EnableJwtProvider; | ||
import io.wwan13.wintersecurity.config.JwtProviderConfigurer; | ||
import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; | ||
import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
|
||
@TestConfiguration | ||
@EnableJwtProvider | ||
public class JwtProviderTestConfig implements JwtProviderConfigurer { | ||
|
||
@Override | ||
public void configureJwt(JwtPropertiesRegistry registry) { | ||
registry | ||
.accessTokenValidity(100000000000L) | ||
.refreshTokenValidity(100000000000L); | ||
} | ||
|
||
@Override | ||
public void configureSecretKey(SecretKeyRegistry registry) { | ||
registry | ||
.secretKey("asdfghjklqwertyuiopzxcvbnmasddfgwerasf"); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestContextTest.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,29 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 io.wwan13.wintersecurity.context.securerequest; | ||
|
||
import io.wwan13.wintersecurity.ContextTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Import(SecureRequestTestConfig.class) | ||
public class SecureRequestContextTest extends ContextTest { | ||
|
||
@Test | ||
void contextLoad() { | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/io/wwan13/wintersecurity/context/securerequest/SecureRequestTestConfig.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,54 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* 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 io.wwan13.wintersecurity.context.securerequest; | ||
|
||
import io.wwan13.wintersecurity.auth.authorizedrequest.support.AuthorizedRequestRegistry; | ||
import io.wwan13.wintersecurity.config.EnableSecureRequest; | ||
import io.wwan13.wintersecurity.config.SecureRequestConfigurer; | ||
import io.wwan13.wintersecurity.resolve.RequestUserId; | ||
import io.wwan13.wintersecurity.resolve.RequestUserRoles; | ||
import io.wwan13.wintersecurity.resolve.support.TargetAnnotationsRegistry; | ||
import io.wwan13.wintersecurity.secretkey.support.SecretKeyRegistry; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
|
||
@TestConfiguration | ||
@EnableSecureRequest | ||
public class SecureRequestTestConfig implements SecureRequestConfigurer { | ||
|
||
@Override | ||
public void configureSecretKey(SecretKeyRegistry registry) { | ||
registry | ||
.secretKey("asdfghjklqwertyuiopzxcvbnmasddfgwerasf"); | ||
} | ||
|
||
@Override | ||
public void registerAuthPatterns(AuthorizedRequestRegistry registry) { | ||
registry | ||
.uriPatterns("/api/test/**") | ||
.allHttpMethods() | ||
.permitAll() | ||
|
||
.elseRequestAuthenticated(); | ||
} | ||
|
||
@Override | ||
public void registerTargetAnnotations(TargetAnnotationsRegistry registry) { | ||
registry | ||
.addSubjectResolveAnnotation(RequestUserId.class) | ||
.addRolesResolveAnnotation(RequestUserRoles.class); | ||
} | ||
} |