forked from hs-web/hsweb-framework
-
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.
- Loading branch information
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
...-starter/src/test/groovy/org/hswebframework/web/authorization/starter/FixBug91Test.groovy
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,69 @@ | ||
package org.hswebframework.web.authorization.starter | ||
|
||
import org.hswebframework.web.authorization.AuthenticationManager | ||
import org.hswebframework.web.authorization.simple.PlainTextUsernamePasswordAuthenticationRequest | ||
import org.hswebframework.web.entity.authorization.UserEntity | ||
import org.hswebframework.web.service.authorization.UserService | ||
import org.hswebframework.web.validate.ValidationException | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.context.ConfigurableApplicationContext | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.test.context.ContextConfiguration | ||
import org.springframework.test.context.web.WebAppConfiguration | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
@WebAppConfiguration | ||
@ContextConfiguration | ||
@SpringBootTest(classes = [TestApplication.class], properties = ["classpath:application.yml"]) | ||
@Configuration | ||
class FixBug91Test extends Specification { | ||
|
||
@Autowired | ||
private ConfigurableApplicationContext context; | ||
|
||
@Shared | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private AuthenticationManager authenticationManager; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
void setup() { | ||
mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); | ||
UserEntity userEntity = userService.createEntity(); | ||
userEntity.setName("test"); | ||
userEntity.setUsername("fix-bug#91"); | ||
userEntity.setPassword("fix-bug#91"); | ||
if (userService.selectByUsername("fix-bug#91") == null) { | ||
userService.insert(userEntity); | ||
} | ||
} | ||
|
||
boolean authenticationInitSuccess(String username, String password) { | ||
try { | ||
def autz = authenticationManager.authenticate(new PlainTextUsernamePasswordAuthenticationRequest(username, password)); | ||
if (autz != null) { | ||
return null != authenticationManager.getByUserId(autz.getUser().getId()); | ||
} | ||
} catch (ValidationException e) { | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
def "同时获取配置文件和数据库中的用户权限"() { | ||
expect: | ||
authenticationInitSuccess(username, password) == success | ||
where: | ||
username | password | success | ||
"fix-bug#91" | "fix-bug#91" | true | ||
"fix-bug-91-in-yml" | "fix-bug-91-in-yml" | true | ||
"not-exists-user" | "not-exists-user" | false | ||
} | ||
} |
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