-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NU-1821][NU-1822] BASE64 helper and from/to JSON conversions (#6995)
- Loading branch information
1 parent
2224d33
commit e6e3f23
Showing
11 changed files
with
280 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
utils/default-helpers/src/main/scala/pl/touk/nussknacker/engine/util/functions/base64.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package pl.touk.nussknacker.engine.util.functions | ||
|
||
import pl.touk.nussknacker.engine.api.{Documentation, HideToString, ParamName} | ||
|
||
import java.util.Base64 | ||
|
||
object base64 extends Base64Utils | ||
|
||
trait Base64Utils extends HideToString { | ||
|
||
@Documentation(description = "Decode Base64 value to String") | ||
def decode(@ParamName("value") value: String): String = { | ||
new String(Base64.getDecoder.decode(value.getBytes("UTF-8"))) | ||
} | ||
|
||
@Documentation(description = "Encode String value to Base64") | ||
def encode(@ParamName("value") value: String): String = { | ||
new String(Base64.getEncoder.encode(value.getBytes("UTF-8"))) | ||
} | ||
|
||
@Documentation(description = "Decode URL-safe Base64 value to String") | ||
def urlSafeDecode(@ParamName("value") value: String): String = { | ||
new String(Base64.getUrlDecoder.decode(value.getBytes("UTF-8"))) | ||
} | ||
|
||
@Documentation(description = "Encode String value to URL-safe Base64") | ||
def urlSafeEncode(@ParamName("value") value: String): String = { | ||
new String(Base64.getUrlEncoder.withoutPadding().encode(value.getBytes("UTF-8"))) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...lt-helpers/src/test/scala/pl/touk/nussknacker/engine/util/functions/Base64UtilsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package pl.touk.nussknacker.engine.util.functions | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class Base64UtilsSpec extends AnyFunSuite with BaseSpelSpec with Matchers { | ||
|
||
test("encode") { | ||
evaluate[String]("#BASE64.encode('{\"foo\": 1}')") shouldBe "eyJmb28iOiAxfQ==" | ||
evaluate[String]("#BASE64.encode('')") shouldBe "" | ||
} | ||
|
||
test("decode") { | ||
evaluate[String]("#BASE64.decode('eyJmb28iOiAxfQ==')") shouldBe """{"foo": 1}""" | ||
evaluate[String]("#BASE64.decode('')") shouldBe "" | ||
} | ||
|
||
test("urlSafeEncode") { | ||
evaluate[String]("#BASE64.urlSafeEncode('{\"foo\": 1}')") shouldBe "eyJmb28iOiAxfQ" | ||
evaluate[String]("#BASE64.urlSafeEncode('')") shouldBe "" | ||
} | ||
|
||
test("urlSafeDecode") { | ||
evaluate[String]("#BASE64.urlSafeDecode('eyJmb28iOiAxfQ')") shouldBe """{"foo": 1}""" | ||
evaluate[String]("#BASE64.urlSafeDecode('')") shouldBe "" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.