Skip to content
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

automation: Handle Outdated Jobs #4560

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

code-sparsh
Copy link
Contributor

@code-sparsh code-sparsh commented Apr 22, 2023

Fixes zaproxy/zaproxy#7799

Changes

  • The Automation tab reloads the plan and the GUI if an extension of a job present in the plan is removed at runtime.

@code-sparsh code-sparsh marked this pull request as draft April 22, 2023 12:38
@code-sparsh code-sparsh changed the title automation: handle outdated jobs automation: Handle Outdated Jobs Apr 22, 2023
System.out.println(plan.getJobIndex(job));
System.out.println(job);

List<AutomationJob> jobs = plan.getJobs();
Copy link
Member

Choose a reason for hiding this comment

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

Could use an advanced for and avoid the intermediate storage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I did try to use the advanced for loop. But it was giving me an exception called ConcurrentModificationException, which was telling me to not change the iterator object (planJob). Although, I wasn't changing it but maybe the function which I was passing that on was changing it. So the only solution I could find on the forums was to just switch to the old for loops.

Copy link
Member

Choose a reason for hiding this comment

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

Does an advanced for work with the intermediate store? Ex: leave this line assigning to “jobs” then iterate it instead of “plan.getJobs”.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does an advanced for work with the intermediate store?

I think, no. It is still giving me that exception on run-time.
Is using the traditional for loop a bad practice though?

Copy link
Member

Choose a reason for hiding this comment

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

Nope, that’s fine. Just trying to simplify 😉

@code-sparsh
Copy link
Contributor Author

code-sparsh commented Apr 22, 2023

Have a look on this please.

I have fixed the cases where it was showing errors. After a job is unregistered, it would be removed from the plan as well as the GUI.

I am using some things like sets, keysets to iterate over the LinkedHashMap. It might not be the most optimized way of doing it maybe, I am not sure. I will try to change it a little if you feel it can be little bit more optimized.

Also, as per the comment by @thc202 zaproxy/zaproxy#7799 (comment)
Do I need to replicate this thing for the case when a job is added (registered) too? Asking this because I couldn't understand if it was even necessary as I couldn't think of a way to reproduce that situation.

Signed-off-by: Sparsh Sethi <sparshsethi15@gmail.com>
@code-sparsh
Copy link
Contributor Author

Added the test case for it.

Also, are there no test cases present (or needed) for the Automation GUI?

@thc202
Copy link
Member

thc202 commented Apr 22, 2023

Do I need to replicate this thing for the case when a job is added (registered) too?

Yes, that happens when the add-on is updated, rather than just being uninstalled. That case should still work, the plan will still have the job but the new version. (Note that we should not be changing the contents of the plan.)

There are no GUI tests currently.

@code-sparsh
Copy link
Contributor Author

code-sparsh commented Apr 22, 2023

Yes, that happens when the add-on is updated, rather than just being uninstalled. That case should still work, the plan will still have the job but the new version. (Note that we should not be changing the contents of the plan.)

okay okay, got it.
Can you help me in re producing this situation? I mean how to push updates to an addOn in local dev environment?

is it related to copyZapAddOn command?

@thc202
Copy link
Member

thc202 commented Apr 22, 2023

You can install/update the add-ons with the task installZapAddOn (e.g. :aO:reports:iZAO, assuming no API key and listening on default port).

@code-sparsh
Copy link
Contributor Author

code-sparsh commented Apr 25, 2023

One problem I am facing is that, whenever the add-on is updated using the installZapAddOn task, it first uninstalls it (un-registers from Automation) and then installs it again with the new version. Now since the job is already removed from the plan upon uninstallation (based on my current changes), I cant access it in the registerAutomationJob method. How should I proceed with this?
I need to access it so that I add it again with the properties and settings it had before.

@code-sparsh
Copy link
Contributor Author

code-sparsh commented Apr 28, 2023

Update: Still not able to figure out a way to handle that problem.

The first part (add-on uninstallation case) is working fine though. But Since the update process goes like this only (first uninstall then re install), I am not sure if it's even possible to do the second part.

Currently, with these changes an add-on update will remove that job from the plan just like an un-installation instead of retaining that job in the plan with the newer version. But still, it would atleast be able to prevent those exceptions thrown at run-time.

Please let me know your views on this... as I was also wondering if I should just go ahead with the current changes and make it un-draft? Or should I wait and keep the PR the way it is, for now.
@kingthorin @thc202

@ArkaprabhaChakraborty
Copy link
Contributor

ArkaprabhaChakraborty commented May 3, 2023

How about adding the necessary check? If it is present or not? If it is present the default action of uninstall and reinstall fits! if it's not then just installing the latest should be the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants