sonarqube plugin can't use jsonp - json

I try to write a SonarQube widget plugin which accesses Jenkins build information by jsonp(json with padding).
This is my html file:
<p id="id"></p>
<script type="text/javascript">
function display(data){
document.getElementById("id").innerHTML = data.number;
}
</script>
<script type="application/javascript" src="http://MYHOST/job/MYJOB/lastBuild/api/json?jsonp=display"> </script>
the html is running fine on my localhost.
But when the html built as a widget plugin in my sonarqube server, the jsonp get error.
Failed to load resource: the server responded with a status of 403 (jsonp forbidden; implement jenkins.security.SecureRequester)
My SonarQube version is 5.6.
Is there any sonarqube web security policy I didn't get it?

Related

Not able to get the #jack-henry/banno-plugin-framework-bridge module to work

I am integrating #jack-henry/banno-plugin-framework-bridge module in the plugin server. I have installed it globally and copied the banno-plugin-framework-bridge.js from dist folder to the root folder of the plugin server. I then included it in the response HTML as per following
<script type="module">
import { enableRouter } from "./banno-plugin-framework-bridge.js";
enableRouter();
</script>
Is this procedure right?
Also, I get the following error:
Cannot GET /banno-plugin-framework-bridge.js.
What must be going wrong?

Execute script not working for https sites - chrome selenium webdriver

I am trying to execute a javascript as part of my testing.
Below is my chrome driver settings
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("headless");
options.addArguments("--disable-web-security");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--reduce-security-for-testing");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
driver.get("https://samplesite.com/");
And I am trying to execute a script on the site using Javascript executor.
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript(code);
This is not working due to the below error.
The page at 'https://samplesite.com/' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint 'http://localhost:8080/myapi'.
This request has been blocked; the content must be served over HTTPS.
But the same is working when I remove the headless option and execute as a visible browser with a Warning message in the console.
could someone guide me on this.
Looking at the error stack trace says it all :
The page at 'https://samplesite.com/' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint 'http://localhost:8080/myapi'.
This request has been blocked; the content must be served over HTTPS.
The URL https://samplesite.com/ was loaded with HTTPS but the jquery post script is trying to call a a webpage over HTTP
On an https webpage you can only make Jquery/AJAX Request to https webpage only
It would be interesting to know if you are specifying http or https in the Jquery Request.
You also need to ensure that as the data which you are requesting is not in the same domain, the domain providing the data must allow it with CORS or JSONP.

Thymeleaf fails to load resources

Hello i'm trying to render my html page with thymeleaf but it fails to load the .js file. I'm using spring-boot and my file structure is src/main/resources/templates this contains all my html files. My css files are located in src/main/resources/static/css/. My .js files are located in src/main/resources/js/.
Now i tried rendering my guest.html file but it's failing to load resources as i tried inspecting the element on chrome and it displays error message below:
http://localhost:8080/js/bootstrap-formhelpers.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/js/bootstrap.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
Below is the issue in my guest.html file that fails to locate the resources:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" th:src="#{https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js}" ></script>
<script src="../js/bootstrap.min.js" th:src="#{js/bootstrap.min.js}"></script>
<script src="../js/bootstrap-formhelpers.min.js" th:src="#{js/bootstrap-formhelpers.min.js}"></script>
Spring Boot does not serve static content from src/main/resources by default. It serves content from the following classpath locations:
classpath:/META-INF/resources
classpath:/static
classpath:/resources
classpath:/public
Therefor, src/main/resources/static/css is served, but not src/main/resources/js/.
Move the js directory to the src/main/resources/static directory to have it served. Another option is to add a resource handler:
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/js/**")
.addResourceLocations("classpath:/js/");
}
You can also override the spring.resources.staticLocations property.
More information about serving static content with Spring Boot can be found in the Spring Boot Documentation: Static Content.

Cannot use webrtc.io package; JavaScript error on browser

I have just started working with WebRTC. I want to use WebRTC with NodeJS.
Currently I have tried webrtc.io package. When I write a basic code for using WebRTC, I get the following JavaScript error.
Error is :
Uncaught TypeError: Type error
rtc._socket.onopen
Error Location:
webrtc.io.js:65
Here is my code.
CLIENT CODE :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 getUserMedia</title>
<script src="socket.io.min.js" type="text/javascript"></script>
<script src="webrtc.io.js" type="text/javascript"></script>
<script>
rtc.connect('ws://abc.in:8001');
</script>
</head>
<body>
<video id="webcam" width="500" autoplay></video>
</body>
</html>
SERVER CODE :
var webRTC = require('/usr/local/node_modules/webrtc.io').listen( 8001 );
console.log( "Server Listening" );
webRTC.on( "connection", function() {
console.log( "Hi" ); // This gets executed successfully.
});
Q1.
Since "Hi" does get printed successfully, I don't know if JS error is actually making a difference or no. Help me resolve this JS error issue.
Issue also reported here.
Q2.
Hitting http://abc.in:8001/ through browser prints "Not implemented". Is that an issue?
Q3.
I wish to stream the audio+video from a mic and webcam to the server.
I understand that I need to create a peer to peer connection to achieve streaming of audio+video to server. Browser should act as one peer and the server would act as the second peer.
How do I send the WebRTC stream to the server? Lack of documentation of the webrtc.io package isn't helping me either.
Please help
EDIT : Browser used is the latest Google Chrome, Version 31.0.1650.57 m
I uploaded simplest webRTC code at
http://github.com/aungthuya-jse/simplest-webRTC/tree/master
You need to add the node_modules to under of project folder by installing
npm install express
and
npm install webrtc.io
after installation you will see /project-folder/node_modules/express folder and webrtc.io folder

Application Cache works in Tomcat 6.0 but not in weblogic 10.3

I'm working with application cache and I'm facing the below issue:
In Tomcat Server:
When the server is online and if the page is accessed for the first time, the files specified in the manifest file are caught successfully in the application cache.
When the server is offline, when we try to access the cached page, there is an error in the browser console (Application Cache Error event: Manifest fetch failed (-1) which is quite normal as per my findings in the internet) but the application cache works fine.
In Weblogic server:
I tried to run the same code in Weblogic server, in online mode, the files are cached as expected. But in the offline mode, for the first time the page is loaded, it works fine, but when I see the console the status of the application cache goes to OBSOLETE mode and so if I do a refresh of the page again, it throws me a 404 error. Also, I'm not getting the "Application Cache Error event: Manifest fetch failed (-1)" which I get when I try to run the code in tomcat server. Please let me know what's that I'm doing wrong. Below are the files:
index.html
<html manifest="demo.appcache">
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="script.js" ></script>
</head>
<body>
<h1>Basic example of page using Application Cache</h1>
<p>Disconnect from the internet and try to reload this page. It should load without requiring you to connect to the internet.</p>
</body>
</html>
manifest file (demo.appcache)
CACHE MANIFEST
CACHE:
style.css
script.js
index.html
demo.appcache
NETWORK:
*
style.css
body{
background-color: #333;
}
h1{
color: #c94054;
}
p{
color: #fff;
}
script.js
if (!window.applicationCache){
alert('It seems that Application Cache is not supported in this browser. Please use a browser which supports it.');
}
web.xml
<mime-mapping>
<extension>appcache</extension>
<mime-type>text/cache-manifest</mime-type>
</mime-mapping>
This problem comes when the browser encounters the manifest line in the html tag, it tries to download the appcache file from the server. But when the server doesn't have this file it returns 404 error, so the application cache goes to OBSOLETE event.
So in this case, the possible reasons are
1- your server doesn't contain this file
2 - If your server has this file but not returning to the browser, this happens when the server is running but your application is actually undeployed.
So try stopping your server rather than just undeploying your applciation from the server instance.
Hope it works.