Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d1d410c
new manual assertions for v1.1
FadySalama Jun 10, 2021
3de4f35
Merge pull request #205 from Fady222/v1.1-testfest1
egekorkan Jun 10, 2021
a5aa867
remove ==== signs from stdout
egekorkan Jun 18, 2021
c6c94ab
Merge branch 'master' of github.com:thingweb/thingweb-playground into…
egekorkan Jun 18, 2021
86844ff
Merge branch 'v1.1-testfest1' of github.com:thingweb/thingweb-playgro…
egekorkan Jun 18, 2021
c40c66c
handle TDs without id and add example
egekorkan Jun 18, 2021
7ada9fd
add TM assertions
FadySalama Jun 23, 2021
7751019
change json-pointer format to URI reference
FadySalama Jun 23, 2021
6ee280f
remove false assertion
FadySalama Jun 23, 2021
85274b6
rename $def to $defs
FadySalama Jun 23, 2021
c9cd947
add oauth2 JSON schema assertions
FadySalama Jun 26, 2021
2d15100
add json schema assertions for TD
FadySalama Jul 1, 2021
974923a
add new ajv formats
FadySalama Jul 12, 2021
6afb166
correct assertions
FadySalama Jul 12, 2021
b06275f
add ajv formats to core index.js
FadySalama Jul 12, 2021
7930bc9
add ajv formats to package.json
FadySalama Jul 12, 2021
dba837e
fix security array, fix TD duplicate TD ids, fix ajv strict mode, upd…
egekorkan Jul 12, 2021
0fb3608
add yarn in lerna
FadySalama Jul 13, 2021
901d89a
add yarn.lock, remove package-lock.json
FadySalama Jul 13, 2021
c9fd4ba
fix paths for using yarn workspaces
FadySalama Jul 13, 2021
ae413ea
add validation logging
FadySalama Jul 13, 2021
fdf7e96
change uri-references to iri-references
FadySalama Jul 13, 2021
ff8c543
add postinstall script to fix a bug in iri-reference format validator
FadySalama Jul 13, 2021
7d23a31
Revert "add postinstall script to fix a bug in iri-reference format v…
FadySalama Jul 13, 2021
4461be1
Revert "change uri-references to iri-references"
FadySalama Jul 13, 2021
9014427
Revert "add validation logging"
FadySalama Jul 13, 2021
ef22349
Revert "fix paths for using yarn workspaces"
FadySalama Jul 13, 2021
2219f7d
Revert "add yarn.lock, remove package-lock.json"
FadySalama Jul 13, 2021
2957422
Revert "add yarn in lerna"
FadySalama Jul 13, 2021
5eedd40
Merge pull request #206 from Fady222/v1.1-testfest1
egekorkan Jul 14, 2021
92aaef5
fix noid thing, package-lock
egekorkan Sep 27, 2021
b1e63f4
Merge branch 'v1.1-testfest1' of github.com:thingweb/thingweb-playgro…
egekorkan Sep 27, 2021
a3a50ad
add installation steps to Readme and install command to package.json
egekorkan Oct 6, 2021
4a46a3d
add todo to readme
egekorkan Nov 2, 2021
bb244ab
add also for additionalResponses
egekorkan Nov 2, 2021
1d40efe
add additionalResponses example
egekorkan Nov 2, 2021
28a48a2
implement check of multiple rel:type in links
egekorkan Nov 3, 2021
3d39a32
remove comment
egekorkan Nov 3, 2021
a4f518e
adjust tests to take linksRelTypeCount
egekorkan Nov 3, 2021
26bf27e
fix valid example to show no warning
egekorkan Nov 3, 2021
5f8ae02
add full flag for warning validation
egekorkan Nov 3, 2021
0a26393
update copyright date on web page
egekorkan Nov 3, 2021
58b83e7
change license to 2021
egekorkan Nov 3, 2021
3b4b20d
document how to add script assertions, update license path in readme
egekorkan Nov 3, 2021
d7cc56f
update license location accross all readmes
egekorkan Nov 3, 2021
8fbdd11
Merge branch 'master' into v1.1-testfest1
egekorkan Mar 1, 2022
0eb363f
fix package-locks
egekorkan Mar 2, 2022
3ada840
after iri support schema spec is not needed
egekorkan Mar 2, 2022
6afcf30
remove double format addition in ajv
egekorkan Mar 2, 2022
b3d362c
bump formats library version
egekorkan Mar 2, 2022
aeb44a4
add td spec schema to track type of support
egekorkan Mar 2, 2022
6d1188b
sync td schema with dirty fix for support
egekorkan Mar 2, 2022
799d2e4
fix examples
egekorkan Mar 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT license

Copyright 2020 Technical University of Munich, Associate Professorship of Embedded Systems and Internet of Things
Copyright 2021 Technical University of Munich, Associate Professorship of Embedded Systems and Internet of Things

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
64 changes: 9 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion packages/assertions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ You can use this package to integrate TD assertion testing in your own Browser/N

## License

Licensed under the MIT license, see [License](./LICENSE.md).
Licensed under the MIT license, see [License](../../LICENSE.md).

## Script based Thing Description Validation

Expand All @@ -67,6 +67,8 @@ This is a Node.js based tool.

## Script based Assertion Tester

TODO: Update these numbers

297 out of 349 assertions of the TD specification can be tested with this tool.

This tool checks which assertions are satisfied by a given Thing Description(s). The assertions are modeled as JSON Schema or as scripts. 'AssertionTester/Assertions' has the JSON Schema assertions.
Expand All @@ -77,6 +79,8 @@ To use the assertion testing via the command line please use the `cli` package.

### Contributing

1. Schema based assertions

You can contribute by providing new JSON Schemas for assertions or by correcting them. There are two types of assertions:

* Not-complex: This is generally used to check assertions that are in the Thing instance or mandatory assertions. You simply put the JSON key to be checked in the `required` validation keyword.
Expand All @@ -90,6 +94,20 @@ You can contribute by providing new JSON Schemas for assertions or by correcting

This way, the validation will surely fail at the const keyword and display that the JSON data has to be `"td-data-schema_description=pass"` string. This will be then detected by the assertion testing tool which will look for the `=` sign to find the result. If the schema doesn't fail, it implies that this if was false, which in turn implies that the assertion you wanted to test was not implemented in the given TD.

2. Script based assertions

Some assertions cannot be verified just by a schema, even when the complex schemas are used.
Examples are checking that all multi language definitions like titles and descriptions contain the same language tags.

When a new one is added, it is advised to add it to the [shared.js](https://github.com/thingweb/thingweb-playground/blob/master/packages/core/shared.js) since such checks can be used by the core package as well.

After adding the function, you should do the following:
1. Add it to the exports of `shared.js`
2. Add it to the exports of `index.js` of the core package
3. Add its name to the details object in `index.js` and its description to the detailComments of the `index.js`
4. In the assertions package, adding it to the imports at the [assertionTests.js](https://github.com/thingweb/thingweb-playground/blob/master/packages/assertions/assertionTests.js)
5. In the same file, calling it whenever needed. The other ones are done at around line 80.
6. Adding it to the expected results of the tests (refResults) at the core package.
## Known Bugs

* td-json-open assertion exists multiple times, [see issue 124](https://github.com/thingweb/thingweb-playground/issues/124)
Expand Down
23 changes: 16 additions & 7 deletions packages/assertions/assertionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
const isUtf8 = require('is-utf8')

// The usual library used for validation
const Ajv = require('ajv')

const Ajv = require("ajv")
const addFormats = require("ajv-formats")
const apply = require('ajv-formats-draft2019');


// Imports from playground core
const checkUniqueness = require('@thing-description-playground/core').propUniqueness
const checkMultiLangConsistency = require("@thing-description-playground/core").multiLangConsistency
const checkSecurity = require("@thing-description-playground/core").security
const checkLinksRelTypeCount = require("@thing-description-playground/core").checkLinksRelTypeCount
const tdSchema = require("@thing-description-playground/core/td-schema.json")

/**
Expand All @@ -28,7 +31,8 @@ function validate(tdData, assertions, manualAssertions, logFunc) {
// a JSON file that will be returned containing the result for each assertion as a JSON Object
let results = []
// !!! uses console info on purpose, to be able to deactivate it, without overwriting console.log !!!
console.info("=================================================================")
// console.info("=================================================================")
// it is commented out to make sure that the output to std is also a valid csv file

// check whether it is a valid JSON
let tdJson
Expand Down Expand Up @@ -71,6 +75,7 @@ function validate(tdData, assertions, manualAssertions, logFunc) {
// additional checks
results.push(...checkSecurity(tdJson))
results.push(...checkMultiLangConsistency(tdJson))
results.push(...checkLinksRelTypeCount(tdJson))

// Iterating through assertions
for (let index = 0; index < assertions.length; index++) {
Expand All @@ -84,12 +89,14 @@ function validate(tdData, assertions, manualAssertions, logFunc) {
"$comment" (v) {
logFunc("\n!!!! COMMENT", v)
},
"allErrors": true
"allErrors": true,
"strict":false
}
const ajv = new Ajv(ajvOptions)
let ajv = new Ajv(ajvOptions)
ajv = addFormats(ajv) // ajv does not support formats by default anymore
ajv = apply(ajv) // new formats that include iri
ajv.addSchema(schema, 'td')
ajv.addVocabulary(['is-complex', 'also']);
addFormats(ajv)



Expand Down Expand Up @@ -264,10 +271,11 @@ module.exports = validate
function checkVocabulary(tdJson) {

const results = []
const ajv = new Ajv()
let ajv = new Ajv({strict: false})
ajv = addFormats(ajv) // ajv does not support formats by default anymore
ajv = apply(ajv) // new formats that include iri
ajv.addSchema(tdSchema, 'td')
ajv.addVocabulary(['is-complex', 'also']);
addFormats(ajv)

const valid = ajv.validate('td', tdJson)
const otherAssertions = ["td-objects_securityDefinitions", "td-arrays_security", "td-vocab-security--Thing",
Expand All @@ -291,6 +299,7 @@ function checkVocabulary(tdJson) {
return results

} else {
console.log(ajv.errorsText())
throw new Error("invalid TD")
}
}
Expand Down
77 changes: 77 additions & 0 deletions packages/assertions/assertions/td-security-oauth2-client-flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"title": "td-security-oauth2-client-flow",
"description": "For the client flow token MUST be included.",
"$schema ": "http://json-schema.org/draft/2019-09/schema#",
"is-complex": true,
"also": ["td-security-oauth2-client-flow-no-auth"],
"type": "object",
"properties": {
"securityDefinitions": {
"type": "object",
"minProperties": 1,
"additionalProperties": {
"$ref": "#/$defs/securityScheme"
}
}
},
"required": [
"securityDefinitions"
],
"additionalProperties": true,
"$defs": {
"securityScheme": {
"if": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"proxy": {
"$ref": "#/$defs/url"
},
"scheme": {
"type": "string",
"enum": [
"oauth2"
]
},
"token": {
"$ref": "#/$defs/url"
},
"refresh": {
"$ref": "#/$defs/url"
},
"scopes": {
"oneOf": [{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
},
"flow": {
"type": "string",
"const":"client"
}
},
"required": [
"scheme", "flow", "token"
],
"not": {
"required": ["authorization"]
}
},
"then": {
"const": "td-security-oauth2-client-flow=pass"
}
},
"url": {
"type": "string",
"format": "uri-reference"
}
}
}
Loading