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.security.client.OpenMetadataJWTClientConfig;
import org.openmetadata.schema.services.connections.metadata.AuthProvider; import org.openmetadata.schema.services.connections.metadata.AuthProvider;
import org.openmetadata.schema.type.EntityReference; import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.utils.EntityInterfaceUtil;
import org.openmetadata.service.Entity; import org.openmetadata.service.Entity;
import org.openmetadata.service.exception.EntityNotFoundException; import org.openmetadata.service.exception.EntityNotFoundException;
import org.openmetadata.service.jdbi3.EntityRepository; import org.openmetadata.service.jdbi3.EntityRepository;
@ -88,10 +89,12 @@ public final class UserUtil {
// user email // user email
updatedUser.setEmail(String.format("%s@%s", username, domain)); updatedUser.setEmail(String.format("%s@%s", username, domain));
} else { } else {
LOG.error( if (Boolean.TRUE.equals(originalUser.getIsBot())) {
String.format( LOG.error(
"You configured bot user %s in initialAdmins config. Bot user cannot be promoted to be an admin.", String.format(
originalUser.getName())); "You configured bot user %s in initialAdmins config. Bot user cannot be promoted to be an admin.",
originalUser.getName()));
}
} }
} catch (EntityNotFoundException e) { } catch (EntityNotFoundException e) {
updatedUser = user(username, domain, username).withIsAdmin(isAdmin).withIsEmailVerified(true); updatedUser = user(username, domain, username).withIsAdmin(isAdmin).withIsEmailVerified(true);
@ -145,7 +148,7 @@ public final class UserUtil {
return new User() return new User()
.withId(UUID.randomUUID()) .withId(UUID.randomUUID())
.withName(name) .withName(name)
.withFullyQualifiedName(name) .withFullyQualifiedName(EntityInterfaceUtil.quoteName(name))
.withEmail(name + "@" + domain) .withEmail(name + "@" + domain)
.withUpdatedBy(updatedBy) .withUpdatedBy(updatedBy)
.withUpdatedAt(System.currentTimeMillis()) .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"); 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 @Test
void put_validUser_200_ok() throws IOException { void put_validUser_200_ok() throws IOException {
// Create user with different optional fields // 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.INGESTION_BOT_NAME;
import static org.openmetadata.service.Entity.TABLE; import static org.openmetadata.service.Entity.TABLE;
import static org.openmetadata.service.exception.CatalogExceptionMessage.entityNotFound; 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.security.SecurityUtil.authHeaders;
import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS;
import static org.openmetadata.service.util.TestUtils.NON_EXISTENT_ENTITY; import static org.openmetadata.service.util.TestUtils.NON_EXISTENT_ENTITY;
@ -107,7 +107,7 @@ class UsageResourceTest extends OpenMetadataApplicationTest {
assertResponse( assertResponse(
() -> reportUsage(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS), () -> reportUsage(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS),
NOT_FOUND, NOT_FOUND,
entityTypeNotFound(invalidEntityType)); entityRepositoryNotFound(invalidEntityType));
} }
@Test @Test
@ -116,7 +116,7 @@ class UsageResourceTest extends OpenMetadataApplicationTest {
assertResponse( assertResponse(
() -> reportUsagePut(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS), () -> reportUsagePut(invalidEntityType, UUID.randomUUID(), usageReport(), ADMIN_AUTH_HEADERS),
NOT_FOUND, NOT_FOUND,
entityTypeNotFound(invalidEntityType)); entityRepositoryNotFound(invalidEntityType));
} }
@Test @Test

View File

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