fix(health): run the context-less health check as the system user #24
No files matched your search
@@ -32,6 +32,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSystemUserSession;
|
||||
import com.kingsrook.qqq.middleware.health.HealthIndicator;
|
||||
import com.kingsrook.qqq.middleware.health.model.metadata.HealthCheckResult;
|
||||
import com.kingsrook.qqq.middleware.health.model.metadata.HealthStatus;
|
||||
@@ -79,7 +80,7 @@ public class BackupsHealthIndicator implements HealthIndicator
|
||||
boolean ownsContext = QContext.getQInstance() == null;
|
||||
if(ownsContext)
|
||||
{
|
||||
QContext.init(qInstance, new QSession());
|
||||
QContext.init(qInstance, systemSession(qInstance));
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -117,4 +118,16 @@ public class BackupsHealthIndicator implements HealthIndicator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The session for a health request that has no QQQ context. It must be the
|
||||
** core system user: token-based authentication modules (OAuth2, Auth0)
|
||||
** reject any other tokenless session, which failed the check on such hosts.
|
||||
*******************************************************************************/
|
||||
static QSession systemSession(QInstance qInstance)
|
||||
{
|
||||
return (new QSystemUserSession(qInstance));
|
||||
}
|
||||
}
|
||||
@@ -116,4 +116,17 @@ class BackupsHealthIndicatorTest
|
||||
QContext.init(qInstance, new com.kingsrook.qqq.backend.core.model.session.QSession());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The indicator's own context runs as the core system user, which token-based
|
||||
** authentication modules accept without a token.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testOwnContextUsesSystemUserSession()
|
||||
{
|
||||
assertThat(BackupsHealthIndicator.systemSession(QContext.getQInstance()))
|
||||
.isInstanceOf(com.kingsrook.qqq.backend.core.model.session.QSystemUserSession.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user