Fix #13347: AdminPrincipals username with dot in it is not created wi… (#13348)

* Fix #13347: AdminPrincipals username with dot in it is not created with quoteFQN

* Fix #13347: AdminPrincipals username with dot in it is not created with quoteFQN

* Fix #13347: AdminPrincipals username with dot in it is not created with quoteFQN

* Fix test with new exception msg being thrown

---------

Co-authored-by: Pere Miquel Brull <peremiquelbrull@gmail.com>
This commit is contained in:
Sriharsha Chintalapani 2023-09-27 06:59:24 -07:00 committed by GitHub
parent 2c3ff8dc08
commit 4d9570c627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 8 deletions

View File

@ -33,6 +33,7 @@ import org.openmetadata.schema.entity.teams.User;
import org.openmetadata.schema.security.client.OpenMetadataJWTClientConfig;
import org.openmetadata.schema.services.connections.metadata.AuthProvider;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.utils.EntityInterfaceUtil;
import org.openmetadata.service.Entity;
import org.openmetadata.service.exception.EntityNotFoundException;
import org.openmetadata.service.jdbi3.EntityRepository;
@ -88,10 +89,12 @@ public final class UserUtil {
// user email
updatedUser.setEmail(String.format("%s@%s", username, domain));
} else {
LOG.error(
String.format(
"You configured bot user %s in initialAdmins config. Bot user cannot be promoted to be an admin.",
originalUser.getName()));
if (Boolean.TRUE.equals(originalUser.getIsBot())) {
LOG.error(
String.format(
"You configured bot user %s in initialAdmins config. Bot user cannot be promoted to be an admin.",
originalUser.getName()));
}
}
} catch (EntityNotFoundException e) {
updatedUser = user(username, domain, username).withIsAdmin(isAdmin).withIsEmailVerified(true);
@ -145,7 +148,7 @@ public final class UserUtil {
return new User()
.withId(UUID.randomUUID())
.withName(name)
.withFullyQualifiedName(name)
.withFullyQualifiedName(EntityInterfaceUtil.quoteName(name))
.withEmail(name + "@" + domain)
.withUpdatedBy(updatedBy)
.withUpdatedAt(System.currentTimeMillis())

View File

@ -245,6 +245,18 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
assertResponse(() -> createEntity(create, ADMIN_AUTH_HEADERS), CONFLICT, "Entity already exists");
}
@Test
void test_adminPrincipalsCreation() throws IOException {
// This is test is ensure adminPrincipals are getting created as expected
// we are hardcoding the usernames as they are passed in config
// Create user with different optional fields
User user = getEntityByName("admin", ADMIN_AUTH_HEADERS);
assertEquals("admin", user.getName());
user = getEntityByName("hello.world", ADMIN_AUTH_HEADERS);
assertEquals("hello.world", user.getName());
}
@Test
void put_validUser_200_ok() throws IOException {
// Create user with different optional fields

View File

@ -21,7 +21,7 @@ import static org.openmetadata.common.utils.CommonUtil.listOf;
import static org.openmetadata.service.Entity.INGESTION_BOT_NAME;
import static org.openmetadata.service.Entity.TABLE;
import static org.openmetadata.service.exception.CatalogExceptionMessage.entityNotFound;
import static org.openmetadata.service.exception.CatalogExceptionMessage.entityTypeNotFound;
import static org.openmetadata.service.exception.CatalogExceptionMessage.entityRepositoryNotFound;
import static org.openmetadata.service.security.SecurityUtil.authHeaders;
import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS;
import static org.openmetadata.service.util.TestUtils.NON_EXISTENT_ENTITY;
@ -107,7 +107,7 @@ class UsageResourceTest extends OpenMetadataApplicationTest {
assertResponse(
() -> reportUsage(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS),
NOT_FOUND,
entityTypeNotFound(invalidEntityType));
entityRepositoryNotFound(invalidEntityType));
}
@Test
@ -116,7 +116,7 @@ class UsageResourceTest extends OpenMetadataApplicationTest {
assertResponse(
() -> reportUsagePut(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS),
NOT_FOUND,
entityTypeNotFound(invalidEntityType));
entityRepositoryNotFound(invalidEntityType));
}
@Test

View File

@ -129,6 +129,7 @@ authorizerConfiguration:
containerRequestFilter: "org.openmetadata.service.security.CatalogOpenIdAuthorizationRequestFilter"
adminPrincipals:
- "admin"
- "hello.world"
# Added only for test purposes and not for production setup
testPrincipals:
- "test"