|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2002-2018 the original author or authors.
|
|
|
+ * Copyright 2002-2021 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.
|
|
@@ -16,6 +16,8 @@
|
|
|
|
|
|
package org.springframework.security.provisioning;
|
|
|
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
|
@@ -23,6 +25,7 @@ import org.springframework.security.core.userdetails.User;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
|
|
|
|
/**
|
|
|
* @author Rob Winch
|
|
@@ -50,4 +53,30 @@ public class InMemoryUserDetailsManagerTests {
|
|
|
.isEqualTo(newPassword);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void constructorWhenUserPropertiesThenCreate() {
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.setProperty("joe", "{noop}joespassword,ROLE_A");
|
|
|
+ properties.setProperty("bob", "{noop}bobspassword,ROLE_A,ROLE_B");
|
|
|
+ InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(properties);
|
|
|
+ assertThat(manager.userExists("joe")).isTrue();
|
|
|
+ assertThat(manager.userExists("bob")).isTrue();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void constructorWhenUserPropertiesWithEmptyValueThenException() {
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.setProperty("joe", "");
|
|
|
+ assertThatIllegalArgumentException().isThrownBy(() -> new InMemoryUserDetailsManager(properties))
|
|
|
+ .withMessage("The entry with username 'joe' could not be converted to an UserDetails");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void constructorWhenUserPropertiesNoRolesThenException() {
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.setProperty("joe", "{noop}joespassword");
|
|
|
+ assertThatIllegalArgumentException().isThrownBy(() -> new InMemoryUserDetailsManager(properties))
|
|
|
+ .withMessage("The entry with username 'joe' could not be converted to an UserDetails");
|
|
|
+ }
|
|
|
+
|
|
|
}
|