Skip to content

Commit

Permalink
Fix use of functions from shared features to new Karate version (#107)
Browse files Browse the repository at this point in the history
* Fix use of functions from shared features to new Karate version
* Disable disputed scenario
  • Loading branch information
edwardsph authored Oct 20, 2023
1 parent e5f29f8 commit 4618210
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# Run the report
- name: Run coverage report
run: ./coverage.sh -d .

# Write index file
- name: Create index.html
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ Feature: RDF documents containing named graphs can be stored and retrieved
And match header Content-Type contains 'application/ld+json'
And assert parse(response, 'application/ld+json', resource.url).contains(expected)

@ignore
Scenario: Alice can GET the JSON-LD with named graph as TTL
# The expected response is disputed - since TTL doesn't support Quads, the RDF spec suggests:
# "If an RDF dataset is returned and the consumer is expecting an RDF graph, the consumer is expected to use the RDF dataset's default graph."
# https://github.com/solid-contrib/specification-tests/pull/101#issuecomment-1491711705
Given header Accept = 'text/turtle'
When method GET
Then status 200
Expand Down
55 changes: 26 additions & 29 deletions web-access-control/protected-operation/common.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ Scenario:
return agentLowerCase !== 'public' ? clients[agentLowerCase].getAuthHeaders(method, url) : {}
}
"""
* def resourcePermissions =
"""
function (modes) {
if (modes && modes !== 'inherited' && modes !== 'no') {
return Object.entries({ R: 'read', W: 'write', A: 'append', C: 'control' })
.filter(([mode, permission]) => modes.includes(mode))
.map(([mode, permission]) => permission)
}
return undefined
}
"""
* def getRequestData =
"""
function (type) {
Expand All @@ -45,26 +34,34 @@ Scenario:
}
}
"""
* def resourceEntry =
"""
function (container, type) {
switch (type) {
case 'plain':
return container.createResource('.txt', 'Hello', 'text/plain')
case 'fictive':
return container.reserveResource('.txt')
case 'rdf':
return container.createResource('.ttl', karate.readAsString('../fixtures/example.ttl'), 'text/turtle')
case 'container':
return container.createContainer()
default:
return undefined
}
}
"""
* def createResource =
"""
function (containerModes, resourceModes, resourceType, subject, agent) {
// define local functions so they are accessible when called from other contexts
resourcePermissions = (modes) => {
if (modes && modes !== 'inherited' && modes !== 'no') {
return Object.entries({ R: 'read', W: 'write', A: 'append', C: 'control' })
.filter(([mode, permission]) => modes.includes(mode))
.map(([mode, permission]) => permission)
}
return undefined
}
resourceEntry = (container, type) => {
switch (type) {
case 'plain':
return container.createResource('.txt', 'Hello', 'text/plain')
case 'fictive':
return container.reserveResource('.txt')
case 'rdf':
return container.createResource('.ttl', karate.readAsString('../fixtures/example.ttl'), 'text/turtle')
case 'container':
return container.createContainer()
default:
return undefined
}
}
const testContainerPermissions = resourcePermissions(containerModes)
const testResourcePermissions = resourcePermissions(resourceModes)
const testContainerInheritablePermissions = resourceModes === 'inherited'
Expand Down Expand Up @@ -115,5 +112,5 @@ Scenario:
return testResource
}
"""
* def getResource = (container, resource, type) => testResources[`${container}:${resource}:${type}`]
* def getResourceKey = (container, resource, type) => `${container}:${resource}:${type}`
* def testResources = resources.reduce((map, t) => { map[`${t.container}:${t.resource}:${t.type}`] = createResource(t.container, t.resource, t.type, subject, agent); return map;}, {})
10 changes: 5 additions & 5 deletions web-access-control/protected-operation/read-access-agent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Only authenticated agents can read (and only that) a resource when gran
* def utils = callonce read('common.feature') ({resources, subject: 'authenticated'})

Scenario Outline: <agent> <result> read a <type> resource (<method>), when an authenticated agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down Expand Up @@ -52,7 +52,7 @@ Feature: Only authenticated agents can read (and only that) a resource when gran
| Public | cannot | HEAD | container | R | inherited | 401 |

Scenario Outline: <agent> <result> <method> to a <type> resource, when an authenticated agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/turtle'
Expand Down Expand Up @@ -83,7 +83,7 @@ Feature: Only authenticated agents can read (and only that) a resource when gran
| Public | cannot | POST | container | R | inherited | [401] |

Scenario Outline: <agent> <result> <method> to a <type> resource, when an authenticated agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/n3'
Expand All @@ -104,7 +104,7 @@ Feature: Only authenticated agents can read (and only that) a resource when gran
| Public | cannot | PATCH | container | R | inherited | 401 |

Scenario Outline: <agent> <result> <method> to a <type> resource, when an authenticated agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/plain'
Expand Down Expand Up @@ -133,7 +133,7 @@ Feature: Only authenticated agents can read (and only that) a resource when gran
| Public | cannot | PATCH | fictive | R | inherited | [401, 405, 415] |

Scenario Outline: <agent> <result> <method> a <type> resource, when an authenticated agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down
10 changes: 5 additions & 5 deletions web-access-control/protected-operation/read-access-bob.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Only Bob can read (and only that) a resource when granted read access
* def utils = callonce read('common.feature') ({resources, subject: 'agent', agent: webIds.bob})

Scenario Outline: <agent> <result> read a <type> resource (<method>), when Bob has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down Expand Up @@ -52,7 +52,7 @@ Feature: Only Bob can read (and only that) a resource when granted read access
| Public | cannot | HEAD | container | R | inherited | 401 |

Scenario Outline: <agent> <result> <method> to a <type> resource, when Bob has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/turtle'
Expand Down Expand Up @@ -83,7 +83,7 @@ Feature: Only Bob can read (and only that) a resource when granted read access
| Public | cannot | POST | container | R | inherited | [401] |

Scenario Outline: <agent> <result> <method> to a <type> resource, when Bob has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/n3'
Expand All @@ -104,7 +104,7 @@ Feature: Only Bob can read (and only that) a resource when granted read access
| Public | cannot | PATCH | container | R | inherited | 401 |

Scenario Outline: <agent> <result> <method> to a <type> resource, when Bob has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/plain'
Expand Down Expand Up @@ -133,7 +133,7 @@ Feature: Only Bob can read (and only that) a resource when granted read access
| Public | cannot | PATCH | fictive | R | inherited | [401, 405, 415] |

Scenario Outline: <agent> <result> <method> a <type> resource, when Bob has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Public agents can read (and only that) a resource when granted read acc
* def utils = callonce read('common.feature') ({resources, subject: 'public'})

Scenario Outline: <agent> <result> read a <type> resource (<method>), when a public agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down Expand Up @@ -56,7 +56,7 @@ Feature: Public agents can read (and only that) a resource when granted read acc
| Public | can | HEAD | container | R | inherited | 200 |

Scenario Outline: <agent> <result> <method> to a <type> resource, when a public agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/turtle'
Expand Down Expand Up @@ -87,7 +87,7 @@ Feature: Public agents can read (and only that) a resource when granted read acc
| Public | cannot | POST | container | R | inherited | [401] |

Scenario Outline: <agent> <result> <method> to a <type> resource, when a public agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/n3'
Expand All @@ -108,7 +108,7 @@ Feature: Public agents can read (and only that) a resource when granted read acc
| Public | cannot | PATCH | container | R | inherited | 401 |

Scenario Outline: <agent> <result> <method> to a <type> resource, when a public agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
And header Content-Type = 'text/plain'
Expand Down Expand Up @@ -137,7 +137,7 @@ Feature: Public agents can read (and only that) a resource when granted read acc
| Public | cannot | PATCH | fictive | R | inherited | [401, 405, 415] |

Scenario Outline: <agent> <result> <method> a <type> resource, when a public agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Only authenticated agents can write (and only that) a resource when gra
* def utils = callonce read('common.feature') ({resources, subject: 'authenticated'})

Scenario Outline: <agent> <result> read a <type> resource (<method>), when an authenticated agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Only Bob can write (and only that) a resource when granted write access
* def utils = callonce read('common.feature') ({resources, subject: 'agent', agent: webIds.bob})

Scenario Outline: <agent> <result> read a <type> resource (<method>), when Bob has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
And headers utils.authHeaders(method, testResource.url, agent)
When method <method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Only authenticated agents can write (and only that) a resource when gra
* def utils = callonce read('common.feature') ({resources, subject: 'public'})

Scenario Outline: <agent> <result> read a <type> resource (<method>), when a public agent has <container> access to the container and <resource> access to the resource
* def testResource = utils.getResource(container, resource, type)
* def testResource = utils.testResources[utils.getResourceKey(container, resource, type)]
Given url testResource.url
When method <method>
Then status <status>
Expand Down

0 comments on commit 4618210

Please sign in to comment.