|
| 1 | +Feature: @subscription ACL variable |
| 2 | + |
| 3 | +# conf-overrides.yml grants role 'user' access to /restheart-test/stripe-gated only when |
| 4 | +# equals[@subscription.plan, "gold"] — see the fileAclAuthorizer permissions list. This |
| 5 | +# proves the chain end to end: a subscription state written to the team document is read |
| 6 | +# by SubscriptionVarResolver and reaches the Undertow predicate engine. |
| 7 | + |
| 8 | +Background: |
| 9 | + * url baseUrl |
| 10 | + * configure followRedirects = false |
| 11 | + |
| 12 | + * def basic = |
| 13 | + """ |
| 14 | + function(creds) { |
| 15 | + var temp = creds.username + ':' + creds.password; |
| 16 | + var Base64 = Java.type('java.util.Base64'); |
| 17 | + var encoded = Base64.getEncoder().encodeToString(temp.toString().getBytes()); |
| 18 | + return 'Basic ' + encoded; |
| 19 | + } |
| 20 | + """ |
| 21 | + * def adminAuth = basic({ username: 'admin', password: 'secret' }) |
| 22 | + |
| 23 | + * def ownerSetup = karate.call('classpath:karate/accounts/helpers/setup-owner.feature') |
| 24 | + * def ownerJwt = ownerSetup.ownerJwt |
| 25 | + * def authHeader = 'Bearer ' + ownerJwt |
| 26 | + |
| 27 | + Given path '/auth/teams' |
| 28 | + And header Authorization = authHeader |
| 29 | + When method GET |
| 30 | + Then status 200 |
| 31 | + * def activeTeams = karate.filter(response, function(x){ return x.active == true }) |
| 32 | + * def teamId = activeTeams[0].id |
| 33 | + |
| 34 | +Scenario: a free-plan owner is denied a path gated on equals[@subscription.plan, "gold"] |
| 35 | + Given path '/restheart-test/stripe-gated/free-owner-doc' |
| 36 | + And header Authorization = authHeader |
| 37 | + And request {} |
| 38 | + When method PUT |
| 39 | + Then status 403 |
| 40 | + |
| 41 | +Scenario: a gold-plan owner is allowed through the same gate |
| 42 | + # Admin writes the subscription state directly — equivalent to what a webhook-driven |
| 43 | + # state update would leave behind. |
| 44 | + Given path '/restheart-test/teams/' + teamId |
| 45 | + And header Authorization = adminAuth |
| 46 | + And request { subscription: { plan: 'gold', status: 'active', seats: 1, cancel_at_period_end: false } } |
| 47 | + When method PATCH |
| 48 | + Then status 200 |
| 49 | + |
| 50 | + Given path '/restheart-test/stripe-gated/gold-owner-doc' |
| 51 | + And header Authorization = authHeader |
| 52 | + And request {} |
| 53 | + When method PUT |
| 54 | + * match [200, 201] contains responseStatus |
| 55 | + |
| 56 | + # Cleanup. |
| 57 | + Given path '/restheart-test/stripe-gated/gold-owner-doc' |
| 58 | + And header Authorization = adminAuth |
| 59 | + When method DELETE |
| 60 | + Then status 204 |
0 commit comments