|
19 | 19 | import org.junit.Assert; |
20 | 20 | import org.junit.Test; |
21 | 21 |
|
| 22 | +import java.util.HashMap; |
| 23 | + |
22 | 24 | public class PasswordTest extends SDKTestCase { |
23 | 25 | @Test |
24 | 26 | public void testGettersOfDefaultPasswords() { |
@@ -129,4 +131,46 @@ public void testPasswordsCompatibleGetByName() { |
129 | 131 | passwords.remove(username); |
130 | 132 | Assert.assertNull(passwords.get(username)); |
131 | 133 | } |
| 134 | + @Test |
| 135 | + public void testPasswordsWithWildCards(){ |
| 136 | + HashMap<String, Object> args = new HashMap<String, Object>(); |
| 137 | + args = Command.defaultValues; |
| 138 | + args.put("owner", "-"); |
| 139 | + args.put("app", "-"); |
| 140 | + args.put("username", "admin"); |
| 141 | + args.put("password", "changed!"); |
| 142 | + Service service = Service.connect(args); |
| 143 | + PasswordCollection passwords = service.getPasswords(); |
| 144 | + Assert.assertEquals(passwords.size(),0); |
| 145 | + |
| 146 | + String name = "no-owner"; |
| 147 | + String value = "sdk-test-password"; |
| 148 | + String realm = "sdk-test-realm"; |
| 149 | + |
| 150 | + Password password; |
| 151 | + // Create a password |
| 152 | + try{ |
| 153 | + password = passwords.create(name, value); |
| 154 | + }catch(IllegalArgumentException e){ |
| 155 | + Assert.assertEquals("While creating StoragePasswords, namespace cannot have wildcards.", e.getMessage()); |
| 156 | + } |
| 157 | + try{ |
| 158 | + password = passwords.create(name, value, realm); |
| 159 | + }catch(IllegalArgumentException e){ |
| 160 | + Assert.assertEquals("While creating StoragePasswords, namespace cannot have wildcards.", e.getMessage()); |
| 161 | + } |
| 162 | + // Remove a password |
| 163 | + try{ |
| 164 | + password = passwords.remove(name); |
| 165 | + }catch(IllegalArgumentException e){ |
| 166 | + Assert.assertEquals("app context must be specified when removing a password.", e.getMessage()); |
| 167 | + } |
| 168 | + try{ |
| 169 | + password = passwords.remove(realm, name); |
| 170 | + }catch(IllegalArgumentException e){ |
| 171 | + Assert.assertEquals("app context must be specified when removing a password.", e.getMessage()); |
| 172 | + } |
| 173 | + passwords = service.getPasswords(); |
| 174 | + Assert.assertEquals(passwords.size(),0); |
| 175 | + } |
132 | 176 | } |
0 commit comments