History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-2081
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Peter Ledbrook
Reporter: Ruslan Roz
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Grails

<g:javascript> tag is working wrong in pair with security plugin

Created: 18/Dec/07 12:33 PM   Updated: Monday 09:09 PM
Component/s: None
Affects Version/s: 1.0.3
Fix Version/s: 1.0.4

Time Tracking:
Not Specified


 Description  « Hide
I have been using the Canoo WebTest plugin for functional testing of Grails application.
When I run following test method:

def testLoginLogOutListNewDelete() {
webtest('teLoginLogOut basic operations: view list, create new entry, view, edit, dele, view') { invoke(url: "http://localhost:8080/LIFT/auth/login") }
}

I get the following errors:

[java] INFO (com.canoo.webtest.steps.request.TargetHelper) - getting response for url: http://localhost:8080/LIFT/auth/login
2007-12-18 15:07:41.192:/LIFT:INFO: GSP servlet initialized
2007-12-18 15:07:44.926:/LIFT:INFO: Initializing Spring FrameworkServlet 'grails-errorhandler'
[java] ERROR (com.gargoylesoftware.htmlunit.html.HtmlPage) - Error loading javascript from [http://localhost:8080/LIFT/plugins/jsecurity-0.1.1/j
/application.js] status=[404 Not Found]
[java] ERROR (com.gargoylesoftware.htmlunit.html.HtmlPage) - Error loading javascript from [http://localhost:8080/LIFT/plugins/jsecurity-0.1.1/j
/application.js]:
[java] com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 404 Not Found for http://localhost:8080/LIFT/plugins/jsecurity-0.1.1/js/app
ication.js
[java] at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:845)
[java] at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:775)
[java] at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:229)

The tag below

<g:javascript library="application"/>

are resolving as

<script type="text/javascript" src="/lift//plugins/jsecurity-0.1.1/js/application.js"></script>

but actually, the path to JS file should be like that

<script type="text/javascript" src="/lift/js/application.js"></script>

So, just for test I've copied JS files from the original location to the web-apps/plugins/jsecurity-0.1.1/ location (where Grails/Canoo is looking for them)

and after that the test was successful.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Peter Ledbrook - 30/Dec/07 06:21 PM
This is actually a tricky problem: the view is in the plugin, but the layout is in the application. So, somehow the plugin context path must be cleared once rendering reaches the layout - easier said than done I think.

In the meantime, I would simply copy login.gsp from the plugin to your grails-app/views/auth directory. This also enables you to customise the look of it.


Peter Ledbrook - 30/Dec/07 06:22 PM
Since it is fairly easy to work around this problem, I'm dropping it down to minor.

Peter Ledbrook - 14/May/08 12:34 PM
Various changes to the plugin have made this issue redundant, I believe. Re-open if it's still a problem for you.

Rogério Carrasqueira - 25/May/08 12:50 PM
Hi,

I had this same problem, I just installed the plugin jsecurity, now on version 0.2 at grails 1.0.2 and the problem appeared again. I made a controller with an create action to add users to my website and when the page was load, the page try to look for the js libraries inside the jsecurity folders, as describe bellow:

<script type="text/javascript" src="/multilinguas//plugins/jsecurity-0.2/js/jquery-1.2.3.cust.js"></script>
<script type="text/javascript" src="/multilinguas//plugins/jsecurity-0.2/js/application.js"></script>

and at my create.gsp I defined on this way:

<g:javascript library="jquery-1.2.3.cust" />
<g:javascript library="application" />

Unfortunately, to avoid this I defined base_href equals to the name of my aplication and I had to call directly the js using the tag <script></script>. The other pages that the controller does not use the Jsecurity, loads normally, without any problems to find the js library.

So I think that a part of this bug remains!

Thanks

Rogério Carraqueira


Lee Butts - 15/Jun/08 05:57 PM - edited
I've also just come across this issue with a fres 1.0.3 app and the lastest jsecuroity pluhin - installed the plugin, ran grails quick-start (which created grails-app/views/auth/login.gsp) and my webtests are failing (after clicking sign in on the login page) due to invalid JS library links on the pages using the main layout.

cheers

Lee


David Doty - 21/Jul/08 09:09 PM
I'm sorry, I am confused by this issue. I too encountered a similar error when using Canoo Webtest and Jsecurity. What is the "fairly easy" workaround to which Peter Ledbrook alludes?

In my grails-app/views/layout/main.gsp file, I replaced the line

<g:javascript library="application"/>

with

<script type="text/javascript" src="/codegrader/js/application.js"></script>

since the latter is how the former is dynamically rendered at run time (unless the bug under discussion incorrectly renders it as mentioned in the previous comments). However, I don't entirely understand the former line (it was placed in main.gsp by default by Grails), and I am afraid that some future change in Grails (for instance, moving the location application.js) will break this.

So what is the correct workaround for this bug?

Thank you in advance,
Dave