eos icon indicating copy to clipboard operation
eos copied to clipboard

DAWN-294 ⁃ need a clear statement of account name business rule and a REGEX to scrub inputs

Open blockone-syncclient opened this issue 8 years ago • 19 comments

The naming restriction for account names is that they be

  • Minimum of 2 characters
  • Maximum of 13 characters
  • First 12 characters can be "a-z" or "1-5" or "."
  • 13th character can only be "a-j" or "1-5"
  • Last character can't be "."
  • Names of length 1 character are in some instances permitted by the code but are not encouraged as a good naming practice

The regex expression used to validate these names in the faucet form is: {code:java} (^[a-z1-5.]{1,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$) {code}

Fix is to update the regex (and the documentation on what names are allowed). The missing part of the naming rule is:

  • the 13th character can only be 1-5 or a-j.

This naming restriction applies to many things, including but not limited to:

  • accounts
  • named permissions
  • contracts

ATC The [web form HERE|https://goo.gl/forms/OHUjugUPTu7Jv1tQ2] should accept and reject, as shown, these inputs to the 'desired account name' field.

Accept:

  • abc
  • a.b
  • .a
  • booleanjulie
  • tbcox123
  • 1.3.5

Reject:

  • .
  • aa.
  • booleanjulien
  • tbcox456
  • tbCOX

blockone-syncclient avatar Dec 14 '17 16:12 blockone-syncclient

➤ Kevin Heifner commented:

  • No more than 13 characters
    • Last character can't be '.'
    • 13th character can only be 1-5a-j (^[a-z1-5.]{1,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)

blockone-syncclient avatar Dec 14 '17 16:12 blockone-syncclient

➤ Kevin Heifner commented:

[~thomas.cox] Where is this documented? I couldn't find it. [~brian.johnson] Does the faucet plugin handle this limitation?

blockone-syncclient avatar Dec 14 '17 16:12 blockone-syncclient

➤ Brian Johnson commented:

You will get the same error that I believe you will get for any interface that is expecting an account_name (or any other name derived type), it will get the "name not properly normalized" exception, since the first thing that will happen is you will convert the passed in json string to an account_name. To return the "unknown key" we would have to fabricate that exception (identify the invalid account_name and then create the same "unkown key" exception since the code's plumbing wouldn't let us pass on the non-compliant account_name.

blockone-syncclient avatar Dec 14 '17 16:12 blockone-syncclient

➤ Kevin Heifner commented:

[~brian.johnson] I think the way it behaves is fine. My question is does this behavior cause issues with your wallet plugin seeing how you generate suggestions?

blockone-syncclient avatar Dec 14 '17 16:12 blockone-syncclient

➤ Thomas B. Cox commented:

Naming of all things (accounts, permissions, etc) follow this rule. Kevin to write a blurb.

blockone-syncclient avatar Dec 14 '17 16:12 blockone-syncclient

Hat tip to Jon-Eric Cook ( @joneric ) for helping chase this down.

thomasbcox avatar Dec 14 '17 16:12 thomasbcox

I have a question about the regex that dictates account names, permission names, contract names. I'm learning about it and am curious where those regex are in the code base?

jonericcook avatar Dec 14 '17 16:12 jonericcook

➤ Brian Johnson commented:

[~kevin.heifner] It just returns the same exception listed above. [~david.atchley]'s site should be designed to anticipate other exceptions.

blockone-syncclient avatar Dec 14 '17 17:12 blockone-syncclient

To accomplish the following: first char is a-z, then 1 to 11 more chars that are a-z or 1-5, and if there's a 13th char it must be a-j or 1-5

Please see the regex below: ^[a-z][a-z1-5]{1,11}[a-j1-5]?$

jonericcook avatar Dec 14 '17 19:12 jonericcook

➤ Brian Johnson commented:

[~thomas.cox] The Description is still missing that '.' can also be used anywhere in the name, except for the last character

So can do: thomas.cox

But cannot do: thomas.cox.

blockone-syncclient avatar Dec 14 '17 21:12 blockone-syncclient

The regex below includes constraints for '.'

^[a-z][a-z1-5\.]{0,10}([a-z1-5]|^\.)[a-j1-5]?$

https://regex101.com/r/tapOhh/5/tests

jonericcook avatar Dec 14 '17 23:12 jonericcook

➤ Kevin Heifner commented:

Type name

  • No more than 13 characters
  • Last character can't be '.'
  • 13th character can only be 1-5a-j (^[a-z1-5.]{1,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)
  • account_name, permission_name, func_name are all of type name

Type type_name

  • string of char up to 32 chars

Types bytes

  • vector of char, limited only by vector platform limit

Type account_permission

struct account_permission { 
    account_name                     account;
    permission_name                  permission;
};Type message

struct message { 
    account_name                     code;
    func_name                        type;
    vector<account_permission>       authorization;
    bytes                            data;
};Type account_permission_weight

struct account_permission_weight { 
    account_permission               permission;
    uint16                           weight;
};Type transaction

struct transaction { 
    uint16                           ref_block_num;
    uint32                           ref_block_prefix;
    time                             expiration;
    vector<account_name>             scope;
    vector<account_name>             read_scope;
    vector<message>                  messages;
};Type signed_transaction

struct signed_transaction : public transaction { 
    vector<signature>                signatures;
};Type key_permission_weight

struct key_permission_weight { 
    public_key                       key;
    uint16                           weight;
};Type authority

struct authority { 
    uint32                           threshold;
    vector<key_permission_weight>    keys;
    vector<account_permission_weight> accounts;
};ABIType type_def

struct type_def { 
    type_name                        new_type_name;
    type_name                        type;
};Type action

struct action { 
    name                             action_name;
    type_name                        type;
};Type table

struct table { 
    name                             table_name;
    type_name                        index_type;
    vector<field_name>               key_names;
    vector<type_name>                key_types;
    type_name                        type;
};Type abi

struct abi { 
    vector<type_def>                 types;
    vector<struct_t>                 structs;
    vector<action>                   actions;
    vector<table>                    tables;
};

blockone-syncclient avatar Dec 15 '17 22:12 blockone-syncclient

➤ Thomas B. Cox commented:

I've saved the REGEX here for general reference: https://regex101.com/r/d8uKrG/1

blockone-syncclient avatar Dec 16 '17 01:12 blockone-syncclient

➤ Thomas B. Cox commented:

Corey can you re-enter the form and ensure it works correctly using the NEW ATC?

blockone-syncclient avatar Dec 16 '17 01:12 blockone-syncclient

Acceptance Test Criteria (ATC) testing results

Rejected

  • .
  • aa.
  • booleanjulien
  • tbcox456
  • tbCOX

Accepted

  • abc
  • a.b
  • .a
  • booleanjulie
  • tbcox123
  • 1.3.5

Note: There is no indication of what is acceptable for the first 12 characters. Maybe the following would be an acceptable description of the naming rules.

  • Minimum of 2 characters
  • Maximum of 13 characters
  • First 12 characters can be "a-z" or "1-5" or "."
  • 13th character can only be "a-j" or "1-5"
  • Last character can't be "."

jonericcook avatar Dec 18 '17 18:12 jonericcook

Passed tests. Thanks to @joneric !

thomasbcox avatar Dec 18 '17 21:12 thomasbcox

➤ Brian Johnson commented:

Sorry, [~thomas.cox], I don't know how I missed this, maybe it was the multiple attempts, but this is the regex:

(^[a-z1-5.]{0,11}[a-z1-5]$)|(^[a-z1-5.]{12}[a-j1-5]$)[~kevin.heifner] please double check me.

So the ATC could also accept "a" and "1".

blockone-syncclient avatar Dec 19 '17 01:12 blockone-syncclient

➤ Kevin Heifner commented:

[~brian.johnson] Your regex is correct.

blockone-syncclient avatar Dec 19 '17 03:12 blockone-syncclient

@blockone-syncclient I think, this regex is uncorrect, because It is inpossible create account, starting from .

aozertsov avatar Sep 07 '18 13:09 aozertsov