naver / ngrinder

enterprise level performance testing solution
naver.github.io/ngrinder
Apache License 2.0
2.02k stars 476 forks source link

nGrinder redirects issue #280

Open srao6277 opened 6 years ago

srao6277 commented 6 years ago

Desktop.zip I am facing an issue when I am scripting the redirects in nGrinder (Script written in Groovy in Eclipse; Eclipse integrated with Groovy plugin) for the URL: https://winterfell-sbo-sbo-test-cso-web-mta.cfapps.sap.hana.ondemand.com/sites Attached is the Eclipse log (Page #11, #12, #13) for your reference and below is the explanation on the issue.

Step#1 I fire a HTTP GET request on https://winterfell-sbo-sbo-test-cso-web-mta.cfapps.sap.hana.ondemand.com/sites. This automatically follows redirects and then lands on to the Login Page: https://winterfell.authentication.sap.hana.ondemand.com/login

Desktop.zip

Step#2 I fire another HTTP GET request on 'https://winterfell.authentication.sap.hana.ondemand.com/saml/discovery?returnIDParam=idp&entityID=winterfell.canary&idp=winterfell-metadata&isPassive=true This doesn't automatically redirect to "Location" header -> https://winterfell.authentication.sap.hana.ondemand.com/saml/login/alias/winterfell.canary?disco=true&idp=xs2security.accounts400.ondemand.com

Refer to the screenshot for more information.

Instead it gets redirected to https://winterfell.authentication.sap.hana.ondemand.com/login We tried to capture and set the csrf cookie for the GET request of https://authentication.sap.hana.ondemand.com/saml/discovery?returnIDParam=idp&entityID=winterfell.canary&idp=winterfell-metadata&isPassive=true -> but still it isn't working as expected

A colleague was able to make this work in JMeter. So we are trying to simulate this in nGrinder by setting "followRedirects" to true and it isn't working as expected.

Since in Step#2, it is not picking up the location of the response header and redirecting back to "/login" page, what could be the possible reasons for this behavior?

we checked if xsuaa is working fine. On executing the request in Postman, everything worked as expected. Curl works well.

junoyoon commented 6 years ago

You may need to add HTTPPluginControl.getConnectionDefaults().followRedirects = true in @BeforeThread

srao6277 commented 6 years ago

Hello Team,

I have already put it in the following snippet:

            @BeforeProcess
            public static void beforeProcess() {
                            HTTPPluginControl.getConnectionDefaults().timeout = 60000;

// HTTPPluginControl.getConnectionDefaults().setProxyServer("proxy.wdf.sap.corp", 8080) //HTTPPluginControl.getConnectionDefaults().useCookies = 1; //HTTPPluginControl.getConnectionDefaults().setFollowRedirects(true); test = new GTest(1, "test-sandbox.ci-iot-sap.cfapps.sap.hana.ondemand.com") request = new HTTPRequest() grinder.logger.info("before process."); }

BR, Sukshatha

From: JunHo Yoon [mailto:notifications@github.com] Sent: Monday, March 19, 2018 8:09 PM To: naver/ngrinder ngrinder@noreply.github.com Cc: Rao, Sukshatha sukshatha.rao01@sap.com; Author author@noreply.github.com Subject: Re: [naver/ngrinder] nGrinder redirects issue (#280)

You may need to add HTTPPluginControl.getConnectionDefaults().followRedirects = true in @beforethread

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/naver/ngrinder/issues/280#issuecomment-374234924, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AhEK9I4FBmn5WfzTZsrvR0rIbLi_mO-vks5tf8L_gaJpZM4Sp1Tt.

srao6277 commented 6 years ago

We have already used follow redirects. Entire code snippet is given below

package groovyproject

import List import String import net.grinder.plugin.http.HTTPRequest import net.grinder.script.GTest import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread

import org.junit.Before import org.junit.BeforeClass import org.junit.Test

import HTTPClient.NVPair import groovyx.net.http.HTTPBuilder import groovyx.net.http.HttpResponseDecorator import groovyx.net.http.URIBuilder import static groovyx.net.http.ContentType.TEXT import static groovyx.net.http.ContentType.HTML import static groovyx.net.http.Method.GET import groovyx.net.http.Method import groovyx.net.http.ContentType import org.apache.http.impl.client.BasicCookieStore import net.grinder.plugin.http.HTTPPlugin import net.grinder.plugin.http.HTTPPluginControl

class Winterfell1 {

            //https://winterfell-sbo-sbo-test-cso-web-mta.cfapps.sap.hana.ondemand.com/sites
                            public static GTest test
                            public static HTTPRequest request
                            public static NVPair[] headers = []
                            public static NVPair[] params = []
                            public static List<String> cookies = []

                            @BeforeClass
                            public static void beforeProcess() {

// grinder=Mockito.mock(InternalScriptContext.class) // TestRegistry testRegistry=Mockito.mock(TestRegistry.class) // Mockito.when(grinder.getTestRegistry()).thenReturn(testRegistry) HTTPPluginControl.getConnectionDefaults().timeout = 6000000 // HTTPPluginControl.getConnectionDefaults().setProxyServer("proxy.wdf.sap.corp", 8080) test = new GTest(1, "test-sandbox.ci-iot-sap.cfapps.sap.hana.ondemand.com") HTTPPluginControl.getConnectionDefaults().setFollowRedirects(true) }

                            @BeforeThread
                            public void beforeThread() {
                                            test.record(this, "test")
                                            grinder.statistics.delayReports=true;
                                            grinder.logger.info("before thread.");
                            }

                            @Before
                            public void before() {
            //                                            request.setHeaders(headers)
            //                                            cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
            //                                            grinder.logger.info("before thread. init headers and cookies");
                            }

                            @Test
                            public void test(){
                                            def http = new HTTPBuilder('https://winterfell-sbo-sbo-test-cso-web-mta.cfapps.sap.hana.ondemand.com/sites')
                                            http.ignoreSSLIssues()

                                            http.request( 'https://winterfell-sbo-sbo-test-cso-web-mta.cfapps.sap.hana.ondemand.com/sites', GET, TEXT ) { req ->
                                                            uri.path = 'https://winterfell-sbo-sbo-test-cso-web-mta.cfapps.sap.hana.ondemand.com/sites'
            //                                            uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
                                                            headers.'User-Agent' = "Mozilla/5.0 Firefox/3.0.4"
                                                            headers.Accept = 'application/json'

                                                            response.success = { HttpResponseDecorator resp, reader ->
                                                            resp.getHeaders('Set-Cookie').each {
                                                                            def cookie = it.value.split(';')[0]
                                                                            println "Adding cookie to collection: $cookie"
                                                                            println "it value: $it.value"
                                                                            cookies.add(cookie)

                                                                            }
                                                            println "Response: ${reader}"
                                            }
                            }
                                            def http1 = new HTTPBuilder('https://winterfell.authentication.sap.hana.ondemand.com/saml/discovery?returnIDParam=idp&entityID=winterfell.canary&idp=winterfell-metadata&isPassive=true')
                                            http1.request( 'https://winterfell.authentication.sap.hana.ondemand.com/saml/discovery?returnIDParam=idp&entityID=winterfell.canary&idp=winterfell-metadata&isPassive=true', GET, HTML ) { request ->
                                                            uri.path = 'https://winterfell.authentication.sap.hana.ondemand.com/saml/discovery?returnIDParam=idp&entityID=winterfell.canary&idp=winterfell-metadata&isPassive=true'
            //                                            uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
                                                            headers.'User-Agent' = "Mozilla/5.0 Firefox/3.0.4"
                                                            headers.Accept = 'application/json'
            //                                            headers['Cookie'] = cookies.join(';')

                                                            }
                                                            }

            }