Skip to content

Commit

Permalink
Merge pull request #2343 from hongwei1/develop
Browse files Browse the repository at this point in the history
bugfix/tweaked the extractCleanRedirectURL method
  • Loading branch information
simonredfern authored Dec 1, 2023
2 parents 34a2c6a + 59802b0 commit e08aee4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
21 changes: 1 addition & 20 deletions obp-api/src/main/scala/code/util/Helper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,8 @@ object Helper extends Loggable {
prettyRender(decompose(input))
}

/**
* extract clean redirect url from input value, because input may have some parameters, such as the following examples <br/>
* eg1: http://localhost:8082/oauthcallback?....--> http://localhost:8082 <br/>
* eg2: http://localhost:8016?oautallback?=3NLMGV ...--> http://localhost:8016
*
* @param input a long url with parameters
* @return clean redirect url
*/
def extractCleanRedirectURL(input: String): Box[String] = {
/**
* pattern eg1: http://xxxxxx?oautxxxx -->http://xxxxxx
* pattern eg2: https://xxxxxx/oautxxxx -->http://xxxxxx
*/
//Note: the pattern should be : val pattern = "(https?):\\/\\/(.*)(?=((\\/)|(\\?))oauthcallback*)".r, but the OAuthTest is different, so add the following logic
val pattern = "([A-Za-z][A-Za-z0-9+.-]*):\\/\\/(.*)(?=((\\/)|(\\?))oauth*)".r
val validRedirectURL = pattern findFirstIn input
// Now for the OAuthTest, the redirect format is : http://localhost:8016?oauth_token=G5AEA2U1WG404EGHTIGBHKRR4YJZAPPHWKOMNEEV&oauth_verifier=53018
// It is not the normal case: http://localhost:8082/oauthcallback?oauth_token=LUDKELGJXRDOC1AK1X1TOYIXM5W1AORFJT5KE43B&oauth_verifier=14062
// So add the split function to select the first value; eg: Array(http://localhost:8082, thcallback) --> http://localhost:8082
val extractCleanURL = validRedirectURL.getOrElse("").split("/oauth")(0)
Full(extractCleanURL)
Full(input.split("\\?oauth_token=")(0))
}

/**
Expand Down
47 changes: 47 additions & 0 deletions obp-api/src/test/scala/code/util/HelperTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Open Bank Project - API
* Copyright (C) 2011-2019, TESOBE GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Email: [email protected]
* TESOBE GmbH.
* Osloer Strasse 16/17
* Berlin 13359, Germany
*
* This product includes software developed at
* TESOBE (http://www.tesobe.com/)
*
*/

package code.util


import code.api.util._
import code.setup.PropsReset
import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers}


class HelperTest extends FeatureSpec with Matchers with GivenWhenThen with PropsReset {

feature("test APIUtil.basicUrlValidation method") {
val testString1 = "http://localhost:8082/oauthcallback?oauth_token=G5AEA2U1WG404EGHTIGBHKRR4YJZAPPHWKOMNEEV&oauth_verifier=53018"
val testString2 = "http://localhost:8082?oauth_token=G5AEA2U1WG404EGHTIGBHKRR4YJZAPPHWKOMNEEV&oauth_verifier=53018"

Helper.extractCleanRedirectURL(testString1).head should be("http://localhost:8082/oauthcallback")
Helper.extractCleanRedirectURL(testString2).head should be("http://localhost:8082")

}

}

0 comments on commit e08aee4

Please sign in to comment.