Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from mtgibbs/bug-fixes
Browse files Browse the repository at this point in the history
Add support for custom ports
  • Loading branch information
mtgibbs authored Oct 25, 2017
2 parents 10ad603 + 4fa8c94 commit 75d708c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.fortify.fod'
version '1.0.2'
version '1.0.3'

apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.dokka'
Expand Down
29 changes: 23 additions & 6 deletions src/main/kotlin/com/fortify/fod/parser/BsiToken.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.fortify.fod.parser

/**
* A Build Server (Continuous) Integration Token for integrating with Fortify on Demand
*/
class BsiToken {

var tenantId: Int = 0
Expand Down Expand Up @@ -27,12 +30,26 @@ class BsiToken {
var technologyVersion: String? = null
var technologyVersionId: Int? = null

// Legacy aliases
var technologyStack: String?
get() { return technologyType }
set(value) { this.technologyType = value }

/**
* Legacy alias for Technology Type
*/
var technologyStack: String?
get() {
return technologyType
}
set(value) {
this.technologyType = value
}

/**
* Legacy alias for Technology Version
*/
var languageLevel: String?
get() { return technologyVersion }
set(value) { this.technologyVersion = value }
get() {
return technologyVersion
}
set(value) {
this.technologyVersion = value
}
}
6 changes: 5 additions & 1 deletion src/main/kotlin/com/fortify/fod/parser/BsiTokenParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.beust.klaxon.string
import com.beust.klaxon.boolean

class BsiTokenParser {

@Throws(URISyntaxException::class, UnsupportedEncodingException::class)
fun parse(token: String): BsiToken {

Expand All @@ -32,6 +33,9 @@ class BsiTokenParser {

if (uri.scheme != null && uri.host != null) {
token.apiUri = "${uri.scheme}://${uri.host}"
if (uri.port > 0) {
token.apiUri = "${token.apiUri}:${uri.port}"
}
}

for (param in params) {
Expand Down Expand Up @@ -59,7 +63,7 @@ class BsiTokenParser {
val stringBuilder = StringBuilder(decodedToken)
val json = parser.parse(stringBuilder) as JsonObject

var token = BsiToken()
val token = BsiToken()

token.tenantId = json.int("tenantId") ?: throw NullPointerException("Tenant Id can not be null.")
token.tenantCode = json.string("tenantCode") ?: throw NullPointerException("Tenant Code can not be null.")
Expand Down
17 changes: 15 additions & 2 deletions src/test/kotlin/com/fortify/fod/parser/tests/BsiTokenParserSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object BsiTokenParserSpec : Spek({
assertEquals("1.8", token.languageLevel)
}

it("should have API URI of 'https://api.ams.fortify.com'") {
it("should have an API URI of 'https://api.ams.fortify.com'") {
assertEquals("https://api.ams.fortify.com", token.apiUri)
}

Expand All @@ -72,6 +72,20 @@ object BsiTokenParserSpec : Spek({
}
}

val bsiUrl4 = "http://127.0.0.1:8888/bsi2.aspx?tid=2222&tc=SourceControl&pv=7812&payloadType=ANALYSIS_PAYLOAD&astid=7&ts=PHP"

on("parsing $bsiUrl4") {
val token = parser.parse(bsiUrl4)

it("should have a Technology Type (Tech Stack) of 'PHP'") {
assertEquals("PHP", token.technologyType)
}

it("should have an API URI of 'http://127.0.0.1:8888'") {
assertEquals("http://127.0.0.1:8888", token.apiUri)
}
}

val bsiToken1 = "eyJ0ZW5hbnRJZCI6MSwidGVuYW50Q29kZSI6IlRlbmFudDEiLCJyZWxlYXNlSWQiOjYsInBheWxvYWRUeXBlIjoiQU5BTFlTSVNfUEFZTE9BRCIsImFzc2Vzc21lbnRUeXBlSWQiOjgsInRlY2hub2xvZ3lUeXBlIjoiX05FVCIsInRlY2hub2xvZ3lUeXBlSWQiOjEsInRlY2hub2xvZ3lWZXJzaW9uIjoiXzRfMCIsInRlY2hub2xvZ3lWZXJzaW9uSWQiOjUsImF1ZGl0UHJlZmVyZW5jZSI6Ik1hbnVhbCIsImF1ZGl0UHJlZmVyZW5jZUlkIjoxLCJpbmNsdWRlVGhpcmRQYXJ0eSI6ZmFsc2UsImluY2x1ZGVPcGVuU291cmNlQW5hbHlzaXMiOmZhbHNlLCJzY2FuUHJlZmVyZW5jZSI6IlN0YW5kYXJkIiwic2NhblByZWZlcmVuY2VJZCI6MSwicG9ydGFsVXJpIjoiaHR0cDovL2ZvZC5sb2NhbGhvc3QiLCJhcGlVcmkiOiIifQ"

on("parsing $bsiToken1") {
Expand Down Expand Up @@ -147,4 +161,3 @@ object BsiTokenParserSpec : Spek({

}
})

0 comments on commit 75d708c

Please sign in to comment.