graph: validate tags properly & add unit tests

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
Merge pull request #8049 from unclejack/fix_tag_validation

graph: validate tags properly & add unit tests