Changeset 19345 in josm for trunk/test
- Timestamp:
- 2025-03-10T17:38:42+01:00 (10 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/auth/CredentialsManagerTest.java
r18650 r19345 2 2 package org.openstreetmap.josm.io.auth; 3 3 4 import org.junit.jupiter.api.Assertions; 5 import org.junit.jupiter.api.Test; 4 6 import org.openstreetmap.josm.testutils.annotations.HTTP; 7 8 import java.net.Authenticator; 9 import java.util.List; 5 10 6 11 /** … … 13 18 return new CredentialsManager(new JosmPreferencesCredentialAgent()); 14 19 } 20 21 @Test 22 public void testMultipleUnsavedHostsLookup() throws CredentialsAgentException { 23 final AbstractCredentialsAgent aca = new JosmPreferencesCredentialAgent(); 24 // A provider that mimics user giving the credentials and choosing not to store them in preferences. 25 AbstractCredentialsAgent.setCredentialsProvider((requestorType, agent, response, username, password, host) -> { 26 response.setUsername("user" + host); 27 response.setPassword("password".toCharArray()); 28 response.setSaveCredentials(false); 29 response.setCanceled(false); 30 }); 31 final CredentialsManager agent = new CredentialsManager(aca); 32 33 String host1 = "example.com"; 34 String host2 = "example.org"; 35 for (String host : List.of(host1, host2)) { 36 // Try to get credentials after "failure" => provider gives the credentials. 37 agent.getCredentials(Authenticator.RequestorType.SERVER, host, true); 38 } 39 // Both hosts should receive their respective credentials. 40 CredentialsAgentResponse response = agent.getCredentials(Authenticator.RequestorType.SERVER, host1, false); 41 Assertions.assertEquals("user" + host1, response.getUsername()); 42 response = agent.getCredentials(Authenticator.RequestorType.SERVER, host2, false); 43 Assertions.assertEquals("user" + host2, response.getUsername()); 44 } 15 45 }
Note:
See TracChangeset
for help on using the changeset viewer.