Skip to content

Commit

Permalink
consider all connections of a strategy when filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Sep 7, 2016
1 parent 5a71192 commit 3a7b68c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/src/main/java/com/auth0/android/lock/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ private List<Strategy> filterSocialStrategies(List<Strategy> strategies, Set<Str
}
List<Strategy> filtered = new ArrayList<>(strategies.size());
for (Strategy strategy : strategies) {
final boolean allowed = connections.isEmpty() || connections.contains(strategy.getDefaultConnectionName());
if (allowed && strategy.getDefaultConnectionName() != null) {
filtered.add(strategy);
for (Connection connection : strategy.getConnections()) {
if (connections.isEmpty() || connections.contains(connection.getName())) {
filtered.add(strategy);
break;
}
}
}
return filtered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public boolean isActiveFlowEnabled() {
*/
@Nullable
public String getDefaultConnectionName() {
if (!connections.isEmpty()) {
return connections.get(0).getName();
}
return null;
return !connections.isEmpty() ? connections.get(0).getName() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@ public void shouldReturnEmptyPasswordlessStrategiesIfNoneMatch() throws Exceptio
assertThat(strategy, is(nullValue()));
}

@Test
public void shouldNotReturnDuplicatedSocialStrategies() throws Exception {
configuration = filteredConfigBy("twitter", "twitter-dev");
final List<Strategy> strategies = configuration.getSocialStrategies();
assertThat(strategies, hasItems(isStrategy(Twitter)));
assertThat(strategies, hasSize(1));
}

@Test
public void shouldReturnUnfilteredSocialStrategiesWithConnections() throws Exception {
configuration = unfilteredConfig();
Expand Down
3 changes: 3 additions & 0 deletions lib/src/test/resources/appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
"name": "twitter",
"connections": [{
"name": "twitter"
},
{
"name": "twitter-dev"
}]
}, {
"name": "linkedin",
Expand Down

0 comments on commit 3a7b68c

Please sign in to comment.