Skip to content

migrate PO00{1,2,3,4,5} to ST00{3,4,5,6,7} #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 27, 2022

Conversation

DinoChiesa
Copy link
Collaborator

This fixes issue #339

  • To consider Condition placements, and to report line numbers on the endpoint file, these checks should be on the Step, not on the Policy, and should use onProxyEndpoint and onTargetEndpoint. Therefore move PO00{1,2,3,4,5} to ST00{3,4,5,6,7}, and re-factor those plugins so they report on the Endpoints.

  • Also introduce new tests for these cases, for Sharedflows.

  • And modify the Endpoint module so that it correctly reports errors in Sharedflows. (This never worked!) And introduce new tests to verify that this is working correctly. With this change, I see that EP002 and PD005 are incorrectly reporting errors on Step elements within SharedFlows. I will fix that in a subsequent PR.

- To consider Condition placements, and to report line numbers on the endpoint
  file, checks must be on Step, not Policy. Therefore move PO00{1,2,3,4,5}
  to ST00{3,4,5,6,7}, and re-design those plugins so they report on the Endpoint.

- Also introduce new tests for these cases, for Sharedflows.

- And modify Endpoint so that it correctly reports errors in Sharedflows.
  (This never worked!)  And introduce new tests to verify that this is
  working correctly.
@DinoChiesa
Copy link
Collaborator Author

Also see the PR #343

@@ -27,13 +27,31 @@ const plugin = {
"A check for a body element must be performed before policy execution.",
fatal: false,
severity: 2, //error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to warning

@@ -27,13 +26,31 @@ const plugin = {
"A check for a body element must be performed before policy execution.",
fatal: false,
severity: 2, //error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to warning

@kurtkanaskie
Copy link
Contributor

Given a policy with:

<ExtractVariables continueOnError="false" enabled="true" name="Extract-Variables-FormParam">
  <DisplayName>Extract Variables-FormParam</DisplayName>
  <FormParam name="greeting">
    <Pattern>hello {user}</Pattern>
  </FormParam>
  <Variable name="name"/>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

I get 3 errors - ST005 - for the steps using Extract-Variables-FormParam policy.
I don't get those errors in the version 2.30.

  <PreFlow name="PreFlow">
    <Request>
      <Step>
        <Condition>(request.content != null)</Condition>
        <Name>Extract-Variables-1</Name>
      </Step>
      <Step>
        <Condition>(request.formparams.count != 0)</Condition>
        <Name>Extract-Variables-FormParam</Name>
      </Step>
      <Step>
        <Condition>(request.formparams.greeting)</Condition>
        <Name>Extract-Variables-FormParam</Name>
      </Step>
      <Step>
        <Condition>(request.content != null)</Condition>
        <Name>Extract-Variables-FormParam</Name>
      </Step>
      <Step>
        <Condition>(request.content != null)</Condition>
        <Name>Extract-Variables-1</Name>
      </Step>
    </Request>
    <Response/>
  </PreFlow>

- also add tests for specific formparams
@DinoChiesa
Copy link
Collaborator Author

I have modified ST005 , so that the condition must be one of these:

  1. request.formstring != null
  2. request.formparam.PARAMNAME != null, where PARAMNAME is the name cited in the policy in the FormParam element.

If there are multiple FormParam elements, then the plugin checks for a condition that checks at least one of them.

@DinoChiesa
Copy link
Collaborator Author

More changes coming. . . . .

@kurtkanaskie
Copy link
Contributor

kurtkanaskie commented Sep 27, 2022

This took me awhile to find, given a policy without a Source element (optional - default uses message) or with a Source element that is anything but <Source>request</Source> I get insufficient Condition.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables continueOnError="false" enabled="true" name="Extract-Variables-FormParam">
  <DisplayName>Extract Variables-FormParam</DisplayName>
  <FormParam name="greeting">
    <Pattern>hello {user}</Pattern>
  </FormParam>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

These Conditions are insufficient without a Source element in the policy.

    <Request>
      <Step>
        <Condition>request.formstring != null</Condition>
        <Name>Extract-Variables-FormParam</Name>
      </Step>
      <Step>
        <Condition>request.formparam.greeting != null</Condition>
        <Name>Extract-Variables-FormParam</Name>
      </Step>

Easy to reproduce, just remove Source element from your test policy in EV-Formparam-1.xml

Also, I think we should add the test conditions to the warning message, it took me a while to figure out the right Condition.

Perhaps:
Use <Condition>request.formstring != null</Condition> or <Condition>request.formparam.PARAMNAME_FROM_POLICY != null</Condition>

these messages now include example conditions
@ssvaidyanathan
Copy link
Collaborator

@DinoChiesa - Should we add a note in the README about the plugin rule change from PO to ST?

@ssvaidyanathan ssvaidyanathan merged commit 9e689f4 into apigee:master Sep 27, 2022
@DinoChiesa DinoChiesa deleted the issue339 branch September 16, 2023 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants