use of com.artipie.front.auth.YamlCredentials in project front by artipie.
the class GetUserTest method returnsUserInfo.
@ParameterizedTest
@CsvSource(value = { "Alice;{\"Alice\":{\"email\":\"alice@example.com\",\"groups\":[]}}", "John;{\"John\":{\"groups\":[\"reader\",\"dev-lead\"]}}", "Mark;{\"Mark\":{\"email\":\"Mark@example.com\",\"groups\":[\"admin\",\"writer\"]}}" }, delimiterString = ";")
void returnsUserInfo(final String name, final String res) throws JSONException {
final var rqs = Mockito.mock(Request.class);
Mockito.when(rqs.params(GetUser.USER_PARAM.toString())).thenReturn(name);
JSONAssert.assertEquals(new GetUser(new YamlCredentials(YamlCredentialsTest.credYaml(YamlCredentialsTest.PasswordFormat.SIMPLE, // @checkstyle LineLengthCheck (5 lines)
new YamlCredentialsTest.User("Alice", Optional.of("alice@example.com")), new YamlCredentialsTest.User("John", Optional.empty(), "reader", "dev-lead"), new YamlCredentialsTest.User("Mark", Optional.of("Mark@example.com"), "writer", "admin")))).handle(rqs, Mockito.mock(Response.class)), res, true);
}
use of com.artipie.front.auth.YamlCredentials in project front by artipie.
the class GetUserTest method returnNotFound.
@Test
void returnNotFound() {
final var rqs = Mockito.mock(Request.class);
Mockito.when(rqs.params(GetUser.USER_PARAM.toString())).thenReturn("any");
final Response resp = Mockito.mock(Response.class);
new GetUser(new YamlCredentials(Yaml.createYamlMappingBuilder().add("credentials", Yaml.createYamlMappingBuilder().build()).build())).handle(rqs, resp);
Mockito.verify(resp).status(HttpStatus.NOT_FOUND_404);
}
use of com.artipie.front.auth.YamlCredentials in project front by artipie.
the class HeadUserTest method returnsOkWhenUserFound.
@Test
void returnsOkWhenUserFound() {
final var rqs = Mockito.mock(Request.class);
final String uid = "Alice";
Mockito.when(rqs.params(GetUser.USER_PARAM.toString())).thenReturn(uid);
final Response resp = Mockito.mock(Response.class);
new HeadUser(new YamlCredentials(YamlCredentialsTest.credYaml(YamlCredentialsTest.PasswordFormat.SIMPLE, new YamlCredentialsTest.User(uid, "plain", "123")))).handle(rqs, resp);
Mockito.verify(resp).status(HttpStatus.OK_200);
}
use of com.artipie.front.auth.YamlCredentials in project front by artipie.
the class HeadUserTest method returnsNotFoundWhenUserDoesNotExists.
@Test
void returnsNotFoundWhenUserDoesNotExists() {
final var rqs = Mockito.mock(Request.class);
Mockito.when(rqs.params(GetUser.USER_PARAM.toString())).thenReturn("Someone");
final Response resp = Mockito.mock(Response.class);
new HeadUser(new YamlCredentials(YamlCredentialsTest.credYaml(YamlCredentialsTest.PasswordFormat.SIMPLE, new YamlCredentialsTest.User("John", "plain", "123")))).handle(rqs, resp);
Mockito.verify(resp).status(HttpStatus.NOT_FOUND_404);
}
use of com.artipie.front.auth.YamlCredentials in project front by artipie.
the class ArtipieYaml method credentials.
/**
* Credentials from config.
* @return Credentials
*/
public Credentials credentials() {
final Optional<Key> key = this.fileCredentialsKey();
Optional<YamlMapping> res = Optional.empty();
if (key.isPresent() && this.storage().exists(key.get())) {
try {
res = Optional.of(Yaml.createYamlInput(new String(this.storage().value(key.get()), StandardCharsets.UTF_8)).readYamlMapping());
} catch (final IOException err) {
throw new UncheckedIOException(err);
}
} else if (key.isPresent()) {
res = Optional.of(Yaml.createYamlMappingBuilder().build());
}
return new YamlCredentials(res.orElseThrow(() -> new NotImplementedException("Not implemented yet")));
}
Aggregations