Skip to content

Commit

Permalink
Clarify ordering of auth schemes in ServiceIndex
Browse files Browse the repository at this point in the history
Updates the docs for getEffectiveAuthSchemes to clarify that the
returned auth schemes will be in alphabetical order by shape id
if there is no `auth` trait present. This was always the case due
to the usage of TreeMap, but the documentation didn't explicitly
state it.

Tests were also updated to ensure this ordering.
  • Loading branch information
milesziemer committed Aug 10, 2023
1 parent 665e00f commit e3cb19d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Map<ShapeId, Trait> getAuthSchemes(ToShapeId service) {
*
* <p>The returned map is provided in the same order as the values in the
* {@code auth} trait if an auth trait is present, otherwise the result
* is returned in an undefined order.
* returned is ordered alphabetically by absolute shape id.
*
* <p>An empty map is returned if {@code service} cannot be found in the
* model or is not a service shape.
Expand Down Expand Up @@ -167,7 +167,7 @@ public Map<ShapeId, Trait> getEffectiveAuthSchemes(ToShapeId service) {
*
* <p>The returned map is provided in the same order as the values in the
* {@code auth} trait if an auth trait is present, otherwise the result
* is returned in an undefined order.
* returned is ordered alphabetically by absolute shape id.
*
* <p>An empty map is returned if {@code service} shape cannot be found
* in the model or is not a service shape. An empty map is returned if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.equalTo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -80,10 +83,11 @@ public void getsAuthSchemesOfServiceWithNoAuthTrait() {
Map<ShapeId, Trait> auth = serviceIndex.getEffectiveAuthSchemes(
ShapeId.from("smithy.example#ServiceWithNoAuthTrait"));

assertThat(auth.keySet(), hasSize(3));
assertThat(auth, hasKey(HttpBasicAuthTrait.ID));
assertThat(auth, hasKey(HttpDigestAuthTrait.ID));
assertThat(auth, hasKey(HttpBearerAuthTrait.ID));
List<ShapeId> ids = new ArrayList<>(auth.keySet());
assertThat(ids, hasSize(3));
assertThat(ids.get(0), equalTo(HttpBasicAuthTrait.ID));
assertThat(ids.get(1), equalTo(HttpBearerAuthTrait.ID));
assertThat(ids.get(2), equalTo(HttpDigestAuthTrait.ID));
}

@Test
Expand All @@ -104,10 +108,11 @@ public void getsAuthSchemesOfOperationWithNoAuthTraitAndServiceWithNoAuthTrait()
ShapeId.from("smithy.example#ServiceWithNoAuthTrait"),
ShapeId.from("smithy.example#OperationWithNoAuthTrait"));

assertThat(auth.keySet(), hasSize(3));
assertThat(auth, hasKey(HttpBasicAuthTrait.ID));
assertThat(auth, hasKey(HttpDigestAuthTrait.ID));
assertThat(auth, hasKey(HttpBearerAuthTrait.ID));
List<ShapeId> ids = new ArrayList<>(auth.keySet());
assertThat(ids, hasSize(3));
assertThat(ids.get(0), equalTo(HttpBasicAuthTrait.ID));
assertThat(ids.get(1), equalTo(HttpBearerAuthTrait.ID));
assertThat(ids.get(2), equalTo(HttpDigestAuthTrait.ID));
}

@Test
Expand All @@ -117,9 +122,10 @@ public void getsAuthSchemesOfOperationWithNoAuthTraitAndServiceWithAuthTrait() {
ShapeId.from("smithy.example#ServiceWithAuthTrait"),
ShapeId.from("smithy.example#OperationWithNoAuthTrait"));

assertThat(auth.keySet(), hasSize(2));
assertThat(auth, hasKey(HttpBasicAuthTrait.ID));
assertThat(auth, hasKey(HttpDigestAuthTrait.ID));
List<ShapeId> ids = new ArrayList<>(auth.keySet());
assertThat(ids, hasSize(2));
assertThat(ids.get(0), equalTo(HttpBasicAuthTrait.ID));
assertThat(ids.get(1), equalTo(HttpDigestAuthTrait.ID));
}

@Test
Expand Down

0 comments on commit e3cb19d

Please sign in to comment.