-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new static token type to Syn (#6)
This commit adds the ability to set a static token in the Syn configuration file so that you can easily use a token for testing, connecting to fedora etc.
- Loading branch information
1 parent
80ad06d
commit 274595d
Showing
9 changed files
with
281 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ca.islandora.syn.settings; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Token { | ||
private String user = "islandoraAdmin"; | ||
private List<String> roles = new ArrayList<>(); | ||
private String token = ""; | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(final String user) { | ||
this.user = user; | ||
} | ||
|
||
public List<String> getRoles() { | ||
return roles; | ||
} | ||
|
||
public void setRoles(final String roles) { | ||
this.roles.clear(); | ||
if (!roles.isEmpty()) { | ||
final String[] parts = roles.split(","); | ||
Collections.addAll(this.roles,parts); | ||
} | ||
} | ||
|
||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(final String token) { | ||
this.token = token.trim(); | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
src/test/java/ca/islandora/syn/settings/SettingsParserTokenTest.java
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,82 @@ | ||
package ca.islandora.syn.settings; | ||
|
||
import org.junit.Test; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class SettingsParserTokenTest { | ||
@Test | ||
public void testInvalidVersion() throws Exception { | ||
final String testXml = String.join("\n" | ||
, "<sites version='2'>" | ||
, " <token>" | ||
, " c00lpazzward" | ||
, " </token>" | ||
, "</sites>" | ||
); | ||
|
||
final InputStream stream = new ByteArrayInputStream(testXml.getBytes()); | ||
final Map<String,Token> tokens = SettingsParser.getSiteStaticTokens(stream); | ||
assertEquals(0, tokens.size()); | ||
} | ||
|
||
@Test | ||
public void testTokenNoParams() throws Exception { | ||
final String testXml = String.join("\n" | ||
, "<sites version='1'>" | ||
, " <token>" | ||
, " c00lpazzward" | ||
, " </token>" | ||
, "</sites>" | ||
); | ||
|
||
final InputStream stream = new ByteArrayInputStream(testXml.getBytes()); | ||
final Map<String,Token> tokens = SettingsParser.getSiteStaticTokens(stream); | ||
final Token token = tokens.get("c00lpazzward"); | ||
assertEquals(1, tokens.size()); | ||
assertEquals("c00lpazzward", token.getToken()); | ||
assertEquals("islandoraAdmin", token.getUser()); | ||
assertEquals(0, token.getRoles().size()); | ||
} | ||
|
||
@Test | ||
public void testTokenUser() throws Exception { | ||
final String testXml = String.join("\n" | ||
, "<sites version='1'>" | ||
, " <token user='denis'>" | ||
, " c00lpazzward" | ||
, " </token>" | ||
, "</sites>" | ||
); | ||
|
||
final InputStream stream = new ByteArrayInputStream(testXml.getBytes()); | ||
final Map<String,Token> tokens = SettingsParser.getSiteStaticTokens(stream); | ||
final Token token = tokens.get("c00lpazzward"); | ||
assertEquals(1, tokens.size()); | ||
assertEquals("denis", token.getUser()); | ||
} | ||
|
||
@Test | ||
public void testTokenRole() throws Exception { | ||
final String testXml = String.join("\n" | ||
, "<sites version='1'>" | ||
, " <token roles='role1,role2,role3'>" | ||
, " c00lpazzward" | ||
, " </token>" | ||
, "</sites>" | ||
); | ||
|
||
final InputStream stream = new ByteArrayInputStream(testXml.getBytes()); | ||
final Map<String,Token> tokens = SettingsParser.getSiteStaticTokens(stream); | ||
final Token token = tokens.get("c00lpazzward"); | ||
assertEquals(1, tokens.size()); | ||
assertEquals(3, token.getRoles().size()); | ||
assertTrue(token.getRoles().contains("role1")); | ||
assertTrue(token.getRoles().contains("role2")); | ||
assertTrue(token.getRoles().contains("role3")); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ca.islandora.syn.settings; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TokenTest { | ||
Token token; | ||
|
||
@Before | ||
public void initializeSite() { | ||
this.token = new Token(); | ||
} | ||
|
||
@Test | ||
public void testTokenUser() { | ||
assertEquals("islandoraAdmin", this.token.getUser()); | ||
final String testVal = "test"; | ||
this.token.setUser(testVal); | ||
assertEquals(testVal, this.token.getUser()); | ||
} | ||
|
||
@Test | ||
public void testTokenRoles() { | ||
assertEquals(0, this.token.getRoles().size()); | ||
|
||
this.token.setRoles("test"); | ||
assertEquals(1, this.token.getRoles().size()); | ||
assertEquals("test", this.token.getRoles().get(0)); | ||
|
||
this.token.setRoles("this,is,a,test"); | ||
assertEquals(4, this.token.getRoles().size()); | ||
assertEquals("this", this.token.getRoles().get(0)); | ||
assertEquals("is", this.token.getRoles().get(1)); | ||
assertEquals("a", this.token.getRoles().get(2)); | ||
assertEquals("test", this.token.getRoles().get(3)); | ||
} | ||
|
||
@Test | ||
public void testTokenToken() { | ||
assertTrue(this.token.getToken().isEmpty()); | ||
final String testVal = "test"; | ||
this.token.setToken(testVal); | ||
assertEquals(testVal, this.token.getToken()); | ||
this.token.setToken(" " + testVal); | ||
assertEquals(testVal, this.token.getToken()); | ||
} | ||
} |
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