Skip to content

Commit

Permalink
test : Context tests for auto configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed Jun 6, 2024
1 parent 54f59a0 commit cbb8668
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 0 deletions.
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() {
}
}
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);
}
}
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() {
}
}
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");
}
}
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() {
}
}
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);
}
}

0 comments on commit cbb8668

Please sign in to comment.