/graylog2-server/src/test/java/org/graylog2/rest/models/users/responses/UserSummaryTest.java

https://github.com/Graylog2/graylog2-server · Java · 73 lines · 50 code · 7 blank · 16 comment · 0 complexity · 9379dd9f110f8e4be5546705d45b0d55 MD5 · raw file

  1. /*
  2. * Copyright (C) 2020 Graylog, Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the Server Side Public License, version 1,
  6. * as published by MongoDB, Inc.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * Server Side Public License for more details.
  12. *
  13. * You should have received a copy of the Server Side Public License
  14. * along with this program. If not, see
  15. * <http://www.mongodb.com/licensing/server-side-public-license>.
  16. */
  17. package org.graylog2.rest.models.users.responses;
  18. import com.fasterxml.jackson.databind.JsonNode;
  19. import com.fasterxml.jackson.databind.ObjectMapper;
  20. import com.google.common.collect.ImmutableList;
  21. import org.graylog.grn.GRNRegistry;
  22. import org.graylog.grn.GRNTypes;
  23. import org.graylog.security.permissions.CaseSensitiveWildcardPermission;
  24. import org.graylog.security.permissions.GRNPermission;
  25. import org.graylog2.plugin.database.users.User;
  26. import org.graylog2.shared.bindings.providers.ObjectMapperProvider;
  27. import org.graylog2.shared.security.RestPermissions;
  28. import org.junit.jupiter.api.Test;
  29. import static org.assertj.core.api.Assertions.assertThat;
  30. class UserSummaryTest {
  31. private GRNRegistry grnRegistry = GRNRegistry.createWithBuiltinTypes();
  32. private ObjectMapper objectMapper = new ObjectMapperProvider().get();
  33. private final UserSummary userSummary = UserSummary.create(
  34. "1234",
  35. "user",
  36. "email",
  37. "Hans",
  38. "Dampf",
  39. "Hans Dampf",
  40. ImmutableList.of(new CaseSensitiveWildcardPermission("dashboard:create:123")),
  41. ImmutableList.of(GRNPermission.create(RestPermissions.ENTITY_OWN, grnRegistry.newGRN(GRNTypes.STREAM, "1234"))),
  42. null,
  43. null,
  44. null,
  45. false,
  46. false,
  47. null,
  48. null,
  49. true,
  50. null,
  51. null,
  52. User.AccountStatus.ENABLED
  53. );
  54. @Test
  55. void permissionsSerialization() {
  56. final JsonNode jsonNode = objectMapper.convertValue(userSummary, JsonNode.class);
  57. assertThat(jsonNode.isObject()).isTrue();
  58. assertThat(jsonNode.path("permissions").get(0).asText()).isEqualTo("dashboard:create:123");
  59. }
  60. @Test
  61. void grnPermissionsSerialization() {
  62. final JsonNode jsonNode = objectMapper.convertValue(userSummary, JsonNode.class);
  63. assertThat(jsonNode.isObject()).isTrue();
  64. assertThat(jsonNode.path("grn_permissions").get(0).asText()).isEqualTo("entity:own:grn::::stream:1234");
  65. }
  66. }