-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Anchor-418] Support auth with SEP10 in SEP38 (#1130)
<!-- If you're making a doc PR or something tiny where the below is irrelevant, delete this template and use a short description, but in your description aim to include both what the change is, and why it is being made, with enough context for anyone to understand. --> ### Description Add sep38.requires_sep10 configuration with default value to FALSE ### Context Currently, according to the SEP-38 spec, some of the SEP38 endpoints have SEP-10 as optional. This task seeks ensure we support this optionality by add configurability to these endpoints' SEP-10 requirements. ### Testing Tests were added to verify endpoints url pattern was added to filter if auth is required
- Loading branch information
Showing
9 changed files
with
68 additions
and
4 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
4 changes: 4 additions & 0 deletions
4
platform/src/main/java/org/stellar/anchor/platform/config/PropertySep38Config.java
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package org.stellar.anchor.platform.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import org.stellar.anchor.config.Sep38Config; | ||
|
||
@Data | ||
public class PropertySep38Config implements Sep38Config { | ||
boolean enabled; | ||
|
||
@SerializedName("sep10_enforced") | ||
boolean sep10Enforced; | ||
} |
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
44 changes: 44 additions & 0 deletions
44
platform/src/test/kotlin/org/stellar/anchor/platform/component/SepBeansTest.kt
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,44 @@ | ||
package org.stellar.anchor.platform.component | ||
|
||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.stellar.anchor.auth.JwtService | ||
import org.stellar.anchor.config.* | ||
import org.stellar.anchor.platform.component.sep.SepBeans | ||
|
||
class SepBeansTest { | ||
@MockK(relaxed = true) private lateinit var secretConfig: SecretConfig | ||
@MockK(relaxed = true) lateinit var custodySecretConfig: CustodySecretConfig | ||
@MockK(relaxed = true) lateinit var sep38Config: Sep38Config | ||
private lateinit var jwtService: JwtService | ||
private lateinit var sepBeans: SepBeans | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
secretConfig = mockk(relaxed = true) | ||
custodySecretConfig = mockk(relaxed = true) | ||
sep38Config = mockk(relaxed = true) | ||
jwtService = JwtService(secretConfig, custodySecretConfig) | ||
sepBeans = SepBeans() | ||
} | ||
|
||
@Test | ||
fun `test info, price, prices were excluded in filter when auth not required`() { | ||
val sep10TokenFilter = sepBeans.sep10TokenFilter(jwtService, sep38Config) | ||
assert(!sep10TokenFilter.urlPatterns.contains("/sep38/info")) | ||
assert(!sep10TokenFilter.urlPatterns.contains("/sep38/price")) | ||
assert(!sep10TokenFilter.urlPatterns.contains("/sep38/prices")) | ||
} | ||
|
||
@Test | ||
fun `test info, price, prices endpoints were included in filter when auth required`() { | ||
every { sep38Config.isSep10Enforced } returns true | ||
val sep10TokenFilter = sepBeans.sep10TokenFilter(jwtService, sep38Config) | ||
assert(sep10TokenFilter.urlPatterns.contains("/sep38/info")) | ||
assert(sep10TokenFilter.urlPatterns.contains("/sep38/price")) | ||
assert(sep10TokenFilter.urlPatterns.contains("/sep38/prices")) | ||
} | ||
} |