Skip to content

Commit

Permalink
CB-2317 Verify authenticationName is supported when invoking Pack for…
Browse files Browse the repository at this point in the history
…mulas (#3120)

* CB-2317 Verify authenticationName is supported when invoking Pack formulas

* update
  • Loading branch information
alan-codaio authored Dec 3, 2024
1 parent 66a263d commit 46cc475
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 49 deletions.
35 changes: 29 additions & 6 deletions bundles/thunk_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6393,7 +6393,22 @@ module.exports = (() => {

// runtime/common/helpers.ts
init_buffer_shim();
function findFormula(packDef, formulaNameWithNamespace) {
function verifyFormulaSupportsAuthenticationName(formula, authenticationName) {
const { allowedAuthenticationNames, name: formulaName } = formula;
if (!allowedAuthenticationNames) {
return;
}
if (!authenticationName) {
throw new Error(`Formula ${formulaName} requires an authentication but none was provided`);
}
if (!allowedAuthenticationNames.includes(authenticationName)) {
throw new Error(`Formula ${formulaName} is not allowed for connection with authentication ${authenticationName}`);
}
}
__name(verifyFormulaSupportsAuthenticationName, "verifyFormulaSupportsAuthenticationName");
function findFormula(packDef, formulaNameWithNamespace, authenticationName, {
verifyFormulaForAuthenticationName
} = { verifyFormulaForAuthenticationName: true }) {
const packFormulas = packDef.formulas;
if (!packFormulas) {
throw new Error(`Pack definition has no formulas.`);
Expand All @@ -6410,19 +6425,27 @@ module.exports = (() => {
}
for (const formula of formulas) {
if (formula.name === name) {
if (verifyFormulaForAuthenticationName) {
verifyFormulaSupportsAuthenticationName(formula, authenticationName);
}
return formula;
}
}
throw new Error(`Pack definition has no formula "${name}"${namespace ?? ` in namespace "${namespace}"`}.`);
}
__name(findFormula, "findFormula");
function findSyncFormula(packDef, syncFormulaName) {
function findSyncFormula(packDef, syncFormulaName, authenticationName, {
verifyFormulaForAuthenticationName
} = { verifyFormulaForAuthenticationName: true }) {
if (!packDef.syncTables) {
throw new Error(`Pack definition has no sync tables.`);
}
for (const syncTable of packDef.syncTables) {
const syncFormula = syncTable.getter;
if (syncTable.name === syncFormulaName) {
if (verifyFormulaForAuthenticationName) {
verifyFormulaSupportsAuthenticationName(syncFormula, authenticationName);
}
return syncFormula;
}
}
Expand Down Expand Up @@ -6873,15 +6896,15 @@ module.exports = (() => {
const selectedAuthentication = getSelectedAuthentication(manifest, executionContext.authenticationName);
switch (formulaSpec.type) {
case "Standard" /* Standard */: {
const formula = findFormula(manifest, formulaSpec.formulaName);
const formula = findFormula(manifest, formulaSpec.formulaName, executionContext.authenticationName);
return formula.execute(params, executionContext);
}
case "Sync" /* Sync */: {
const formula = findSyncFormula(manifest, formulaSpec.formulaName);
const formula = findSyncFormula(manifest, formulaSpec.formulaName, executionContext.authenticationName);
return formula.execute(params, executionContext);
}
case "SyncUpdate" /* SyncUpdate */: {
const formula = findSyncFormula(manifest, formulaSpec.formulaName);
const formula = findSyncFormula(manifest, formulaSpec.formulaName, executionContext.authenticationName);
if (!formula.executeUpdate) {
throw new Error(`No executeUpdate function defined on sync table formula ${formulaSpec.formulaName}`);
}
Expand All @@ -6893,7 +6916,7 @@ module.exports = (() => {
return parseSyncUpdateResult(response);
}
case "GetPermissions" /* GetPermissions */: {
const formula = findSyncFormula(manifest, formulaSpec.formulaName);
const formula = findSyncFormula(manifest, formulaSpec.formulaName, executionContext.authenticationName);
if (!formula.executeGetPermissions) {
throw new Error(`No executeGetPermissions function defined on sync table formula ${formulaSpec.formulaName}`);
}
Expand Down
35 changes: 29 additions & 6 deletions dist/bundles/thunk_bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions dist/runtime/common/helpers.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions dist/runtime/common/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/runtime/thunk/thunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions dist/testing/execution.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 46cc475

Please sign in to comment.