Skip to content

Commit

Permalink
add max length check to vouch text (#178)
Browse files Browse the repository at this point in the history
* add maxLength string check

* address pr comments
  • Loading branch information
mmou committed Apr 9, 2020
1 parent 5d74015 commit ec534da
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
19 changes: 14 additions & 5 deletions lib/schema3.js

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

8 changes: 6 additions & 2 deletions lib/wot.js

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

8 changes: 6 additions & 2 deletions src/schema3.iced
Expand Up @@ -165,8 +165,13 @@ class ChainType extends Node
return null

class String extends Node
constructor : ({args}) ->
@_args = args

_check : ({path, obj}) ->
if typeof(obj) isnt 'string' or obj.length is 0 then return mkerr path, "value must be a string"
if (max_length = @_args?.max_length)?
if obj.length > max_length then return mkerr path, "value length needs to be < #{max_length}"
return null

class StringEnum extends Node
Expand All @@ -179,7 +184,6 @@ class StringEnum extends Node
if not @_values[obj] then return mkerr path, "unknown enum value (#{obj})"
return null


class Value extends Node
constructor : (@_value) ->
_check : ({path, obj}) ->
Expand Down Expand Up @@ -227,7 +231,7 @@ exports.time = () -> new Time {}
exports.int = () -> new Int {}
exports.chain_type = () -> new ChainType {}
exports.link_type = () -> new LinkType {}
exports.string = () -> new String {}
exports.string = (args)-> new String { args: args }
exports.value = (v) -> new Value v
exports.bool = () -> new Bool {}
exports.struct = (s) -> new Struct {slots : s}
Expand Down
4 changes: 2 additions & 2 deletions src/wot.iced
Expand Up @@ -59,10 +59,10 @@ exports.Vouch = class Vouch extends Base
confidence : schema.dict({
username_verified_via : schema.string_enum(["in_person", "proofs", "video", "audio", "other_chat", "familiar", "other"]).optional()
proofs: schema.array(proof_schema).optional()
other : schema.string().optional()
other : schema.string({max_length: 90}).optional()
})
failing_proofs : schema.array(proof_schema).optional()
vouch_text : schema.string()
vouch_text : schema.string({max_length: 700})
})
err = schm.check(obj)
cb err
Expand Down
31 changes: 31 additions & 0 deletions test/files/wot.iced
Expand Up @@ -67,3 +67,34 @@ exports.wot_vouch_happy = (T,cb) ->
T.equal outer[4], constants.sig_types_v2.wot.vouch_with_revoke, "revoke picked up"

cb null

exports.wot_vouch_bad = (T,cb) ->
esc = make_esc cb
await new_km_and_sig_arg {}, esc defer me
await new_km_and_sig_arg {}, esc defer them
me.wot =
vouch :
user :
username : them.user.local.username
uid : them.user.local.uid
eldest:
kid : them.sig_eng.km.key.ekid().toString('hex')
seqno : 1
seq_tail :
seqno : 20
sig_id : new_sig_id()
payload_hash : new_payload_hash()
confidence :
username_verified_via : "audio"
other : "this string is longer than 90 char this string is longer than 90 char this string is longer than 90 char this string is longer than 90 char"
vouch_text : "darn rootin tootin"
obj = new wot.Vouch me
await obj.generate_v2 esc(defer(out)), {dohash:true}

verifier = alloc out.inner.obj.body.type, me
varg = { armored : out.armored, skip_ids : true, make_ids : true, inner : out.inner.str, expansions : out.expansions, require_packet_hash :true}
await verifier.verify_v2 varg, defer err
T.assert err?, "got an error back"
T.assert (err.message.indexOf(".confidence.other") >= 0), "found right error message"

cb null

0 comments on commit ec534da

Please sign in to comment.