Grails JCaptcha testing mode - grails

Anyone used the JCaptcha grails plugin know if this has a test mode (for use with automated testing, GEB/Selenium), or do I manually have to add a test parameter to my config file and check this in all controllers where the captcha is checked?

Did not find a test mode, but worked around it by defining a test mode variable in the grails config file.
def captchaOK = false
try {
captchaOK = jcaptchaService.validateResponse("captchaImage", session.id, params.captchaText)
}
}
catch(CaptchaServiceException cse) {
captchaOK = false;
}
Was replaced with:
def captchaOK = false
try {
if(grailsApplication.config.capatchaTestMode == true) {
captchaOK = true;
}
else {
captchaOK = jcaptchaService.validateResponse("captchaImage", session.id, params.captchaText)
}
}
catch(CaptchaServiceException cse) {
captchaOK = false;
}

Related

How to replace Servlet Filters already defined (replacing legacy doWithWebDescriptor with doWithSpring)

I'm trying to upgrade a Grails plugin from version 2.3.4 to 4.0.11. It uses a syntax that is no longer supported to replace filters with names sitemesh and urlMapping with its own filters.
The code below uses a DSL for xml. It replaces xml nodes in the final generated web.xml.
def doWithWebDescriptor = { xml ->
def pageFilter = xml.filter.find { it.'filter-name'.text() == 'sitemesh' }
def urlMappingFilter = xml.filter.find { it.'filter-name'.text() == 'urlMapping' }
def grailsVersion = GrailsUtil.grailsVersion
// Grails 1.3.x & Grails 2.0.x
def pageFilterClass = "org.zkoss.zk.grails.web.ZKGrailsPageFilter"
def urlMappingFilterClass = "org.zkoss.zk.grails.web.ZULUrlMappingsFilter"
if(grailsVersion.startsWith("2")) {
pageFilter.'filter-class'.replaceNode {
'filter-class'(pageFilterClass)
}
urlMappingFilter.'filter-class'.replaceNode {
'filter-class'(urlMappingFilterClass)
}
//
// Require a legacy config for servlet version
//
if(application.metadata.getServletVersion() >= '3.0') {
pageFilter.'filter-class' + {
'async-supported'('true')
}
urlMappingFilter.'filter-class' + {
'async-supported'('true')
}
}
} else {
pageFilter.'filter-class'.replaceBody(pageFilterClass)
urlMappingFilter.'filter-class'.replaceBody(urlMappingFilterClass)
}
}
What I tried so far
The code below uses Grails plugin configuration to register filters with spring's FilterRegistrationBean. I'm following Grails official documentation.
Closure doWithSpring() { { ->
boolean supportsAsync = this.grailsApplication.metadata.getServletVersion() >= "3.0"
pageFilter(FilterRegistrationBean) {
name = "sitemesh"
filter = bean(org.zkoss.zk.grails.web.ZKGrailsPageFilter)
urlPatterns = ["/*"]
order = Ordered.HIGHEST_PRECEDENCE
asyncSupported = supportsAsync
}
urlMappingFilter(FilterRegistrationBean) {
name = "urlMapping"
filter = bean(org.zkoss.zk.grails.web.ZULUrlMappingsFilter)
urlPatterns = ["/*"]
order = Ordered.HIGHEST_PRECEDENCE
asyncSupported = supportsAsync
}
}}
How can I replicate the legacy code with RegistrationBeans?
Also, I don't know if any of these filters got deprecated by Grails. I would like to know if there are any other replacements, if possible.
Here's the project in case anyone wants more context.
Debugging the older version of the plugin I came up with the following:
pageFilter(FilterRegistrationBean) {
name = "sitemesh"
filter = bean(ZKGrailsPageFilter)
urlPatterns = ["/*"]
order = OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER + 50
asyncSupported = supportsAsync
dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR)
}
urlMappingFilter(FilterRegistrationBean) {
name = "urlMapping"
filter = bean(ZULUrlMappingsFilter)
urlPatterns = ["/*"]
order = OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER + 60
asyncSupported = supportsAsync
dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD)
}
Added the dispatcherTypes and changed the order assuming these would be the last filters where the 'pageFilter' should be placed before the 'urlMappingFilter' in the filter chain.

check if a resource is locked

I usually lock resources in my declarative pipeline with something like:
lock(resource: "MY_RESOURCE") {
// do something
}
but now I have several different resources I could use, is there a way to check if a resource is locked?
I would like to do something like:
myResources = ["RES1", "RES2", "RES3"]
hasResource = false
for (resource in myResources) {
if (hasresource) {
break
}
if (!isLocked(resource)) {
hasresource = true
lock(resource) {
// do something
}
}
}
(sorry if the syntax is wrong, I don't really program in groovy very often)
according to the sources of lock plugin this should work:
import org.jenkins.plugins.lockableresources.LockableResourcesManager as LRM
def myResources = ["RES1", "RES2", "RES3"]
def notLocked = myResources.find{rName->
LRM.get().forName(rName).with{ r-> !r.isLocked() && !r.isQueued() }
}
if(notLocked){
lock(notLocked){
//do smth
}
}
To Check if a particular resource is locked or not in jenkins
def manager = org.jenkins.plugins.lockableresources.LockableResourcesManager
def myResources = manager.get().fromName("test2")
//def myLabels = manager.get().allLabels // if you want to filter based on labels
def checkLocked = myResources.find { r ->
!r.isLocked() && !r.isQueued() }
if (checkLocked) {
def myResource = checkLocked.toString()
println myResource + "is locked"
}
else {
println "Specified Resource is not Locked"
}
Maybe not an optimal solution, but we managed to achieve this with following approach:
waitUntil {
lock(resource: 'RES1', skipIfLocked: true){
// do something with RES1
return true; // exit the waiting loop
}
lock(resource: 'RES2', skipIfLocked: true){
// do something with RES2
return true; // exit the waiting loop
}
lock(resource: 'RES3', skipIfLocked: true){
// do something with RES3
return true; // exit the waiting loop
}
}
We did it this way due to the following error we received when we tried to use the accepted answer:
Scripts not permitted to use staticMethod org.jenkins.plugins.lockableresources.LockableResourcesManager get

modify the redirection after confirming the order in prestashop

How I can modify the redirection after confirming the order from history to my account?
I do not know where I can change the code.
I modified the code of the OrderConfirmationController.php page in the overide:
if (Cart::isGuestCartByCartId($this->id_cart)) {
$is_guest = true;
$redirectLink = 'index.php?controller=guest-tracking';
} else {
$redirectLink = 'index.php?controller=history';
}
By:
if (Cart::isGuestCartByCartId($this->id_cart)) {
$is_guest = true;
$redirectLink = 'index.php?controller=guest-tracking';
} else {
$redirectLink = 'index.php?controller=my-account';
}
and I deleted class_index.php located in the cache folder and still I have the same problem the redirection is to the history
You have to override orderConfirmationController.php
Read this document

Xtext project JDT Independence

I created editor with Xtext 2.9.1 and now I want to make it independent of JDT. I followed this guide https://eclipse.org/Xtext/documentation/307_special_languages.html
but it does not seem to work. This is my ErrmsgUiModule.xtend
#FinalFieldsConstructor
class ErrmsgUiModule extends AbstractErrmsgUiModule {
override configure(Binder binder) {
super.configure(binder);
binder.bind(DefaultHighlightingConfiguration).to(ErrMsgHighlightingConfiguration);
binder.bind(DefaultSemanticHighlightingCalculator).to(ErrorSemanticHighlightingCalculator);
}
override bindIResourceForEditorInputFactory() {
return ResourceForIEditorInputFactory
}
override bindIResourceSetProvider() {
return SimpleResourceSetProvider
}
override provideIAllContainersState() {
return Access.getWorkspaceProjectsState()
}
}
I checked every overwritten method with debugger and all 3 methods are called. I did not created my own project wizard so this should be enough.
But still after plugin installating the Java project wizard becomes available...
/Edit:
To provide more information, this is project's mwe2 file
module com.xxx.lang.errmsg.GenerateErrmsg
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
import org.eclipse.xtext.ui.generator.*
var rootPath = ".."
Workflow {
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = "com.xxx.lang.errmsg"
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
}
createEclipseMetaData = true
}
code = {
encoding = "windows-1250"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = StandardLanguage {
name = "com.xxx.lang.errmsg.Errmsg"
fileExtensions = "msg"
fragment = formatting.Formatter2Fragment2 auto-inject {}
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
}
}
}
and this is list of Dependencies from plugin.xml for various projects:
project com.xxx.lang.errmsg
org.eclipse.xtext,
org.eclipse.xtext.xbase,
org.eclipse.equinox.common;bundle-version="3.5.0",
org.eclipse.emf.ecore,
org.eclipse.xtext.xbase.lib,
org.antlr.runtime,
org.eclipse.xtext.util,
org.eclipse.xtend.lib,
org.eclipse.emf.common,
org.objectweb.asm;bundle-version="[5.0.1,6.0.0)";resolution:=optional,
org.eclipse.xtext.ui
project com.xxx.lang.errmsg.ui
com.xxx.lang.errmsg,
com.xxx.lang.errmsg.ide,
org.eclipse.xtext.ui,
org.eclipse.xtext.ui.shared,
org.eclipse.xtext.ui.codetemplates.ui,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.0",
org.eclipse.ui,
org.eclipse.compare,
org.eclipse.xtext.builder,
org.eclipse.xtend.lib;resolution:=optional,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtext.xbase.ui
/Edit2: According to this topic https://bugs.eclipse.org/bugs/show_bug.cgi?id=336217, I also tried to disable all org.eclipse.jdt* plugins in run configuration. This is what i get http://pastebin.com/Wi0gzceM
You have to remove the dependencies on org.eclipse.xtext.xbase and org.eclipse.xtext.xbase.ui from your runtime and UI project.
Make sure if you open the Plug-in Dependencies in the Package Explorer that you do not see org.eclipse.jdt.core in the list. If so, there is another plug-in having a (transitive) dependency. Find out which and remove.

Common way to execute a stored proc from both ColdFusion and Railo

I think I've gotten the most simplest scenario built. I just want to pass it by everyone for a sanity check. Here's the idea:
GetErrorCodes.cfm does the following:
<cfscript>
response = new ErrorCodes().WhereXXX(); // ACF or Railo, doesn't matter
</cfscript>
ErrorCodes.cfc:
function WhereXXX() {
return new sproc().exec('app.GetErrorCodes'); // All my functions will do this instead of executing the sproc themselves.
}
sproc.cfc:
component {
function exec(procedure) {
local.result = {};
if (server.ColdFusion.productname == 'Railo') {
return new Railo().exec(arguments.procedure); // Has to be outside of sproc.cfc because ColdFusion throws a syntax error otherwise.
}
local.svc = new storedProc();
local.svc.setProcedure(arguments.procedure);
local.svc.addProcResult(name='qry');
try {
local.obj = local.svc.execute();
local.result.Prefix = local.obj.getPrefix();
local.result.qry = local.obj.getProcResultSets().qry;
} catch(any Exception) {
request.msg = Exception.Detail;
}
return local.result;
}
Railo.cfc:
component {
function exec(procedure) {
local.result = {};
try {
storedproc procedure=arguments.procedure result="local.result.Prefix" returncode="yes" {
procresult name="local.result.qry";
}
} catch(any Exception) {
request.msg = Exception.Message;
}
return local.result;
}
}
So I've been working on this all day, but tell me, is this a sane way to keep the source code the same if it's to be run on either a ColdFusion server or a Railo server?
Um... just use <cfstoredproc> instead of trying to use two different CFScript approaches that are mutually exclusive to each other of the CFML platforms.

Resources