How to use tokenString method of types Package

Best Ginkgo code snippet using types.tokenString

jwt.go

Source:jwt.go Github

copy

Full Screen

...114}115func CheckToken(tx *types.Transaction, stateDB vm.StateDB) bool {116 if tx.To() != nil && *tx.To() == utils.AccessCtlContract {117 log.Trace("access ctl token verify")118 tokenString, err := ParseToken(tx, stateDB)119 if err != nil {120 log.Error("parse token", "err", err)121 return false122 }123 if !checkJWT(tokenString, "a") {124 return false125 }126 return true127 }128 //DappAuth:T UserAuth:T Deploy:d regular Tx:u/d129 if utopia.ConsortiumConf.DappAuth && utopia.ConsortiumConf.UserAuth {130 tokenString, err := ParseToken(tx, stateDB)131 if err != nil {132 log.Error("parse token", "err", err)133 return false134 }135 //if deploy contract tx must role d136 if tx.To() == nil || *tx.To() == utils.CCBaapDeploy {137 if !checkJWT(tokenString, "d") {138 return false139 }140 } else {141 //if not , regular tx must role u at least142 if !checkJWT(tokenString, "u/d") {143 return false144 }145 }146 }147 //DappAuth:F UserAuth:T Deploy:u/d regular Tx:u/d148 if !utopia.ConsortiumConf.DappAuth && utopia.ConsortiumConf.UserAuth {149 tokenString, err := ParseToken(tx, stateDB)150 if err != nil {151 log.Error("parse token", "err", err)152 return false153 }154 //if deploy contract tx must role d155 if tx.To() == nil || *tx.To() == utils.CCBaapDeploy {156 if !checkJWT(tokenString, "u/d") {157 return false158 }159 } else {160 //if not , regular tx must role u at least161 if !checkJWT(tokenString, "u/d") {162 return false163 }164 }165 }166 //DappAuth:T UserAuth:F Deploy:d regular Tx:-167 if utopia.ConsortiumConf.DappAuth && !utopia.ConsortiumConf.UserAuth {168 //if deploy contract tx must role d169 if tx.To() == nil || *tx.To() == utils.CCBaapDeploy {170 tokenString, err := ParseToken(tx, stateDB)171 if err != nil {172 log.Error("parse token", "err", err)173 return false174 }175 if !checkJWT(tokenString, "d") {176 return false177 }178 }179 }180 //DappAuth:F UserAuth:F Deploy:- regular Tx:-181 return true182}183func checkJWT(tokenString string, roleLimit string) (success bool) {184 if tokenString == "" {185 log.Error("tokenString empty")186 return false187 }188 token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {189 // Don't forget to validate the alg is what you expect:190 if _, ok := token.Method.(*jwt.SigningMethodECDSA); !ok {191 return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])192 }193 if token.Header["alg"] != "ES256" {194 return nil, fmt.Errorf("invalid signing alg:%v, only ES256 is prefered", token.Header["alg"])195 }196 claims, ok := token.Claims.(jwt.MapClaims)197 if !ok {198 return nil, fmt.Errorf("token claims type error")199 }200 ak, ok := claims["ak"]201 if !ok {202 return nil, fmt.Errorf("ak no exist in claims")203 }204 hexPubKey, ok := ak.(string)205 if !ok || len(hexPubKey) != vm.PUBK_HEX_LEN {206 return nil, fmt.Errorf("ak format error")207 }208 //check public key209 _, ok = utopia.UserCertPublicKeyMap[hexPubKey]210 if !ok {211 return nil, fmt.Errorf("ak no exist in user cert public key")212 }213 return crypto.DecompressPubkey(common.Hex2Bytes(hexPubKey))214 })215 if err != nil {216 log.Error("jwt parse", "err", err)217 return false218 }219 if claims, success := token.Claims.(jwt.MapClaims); success && token.Valid {220 limit, success := claims["l"].(float64)221 if !success {222 log.Error("l not correct")223 return false224 }225 if !checkLimit(tokenString, int64(limit)) {226 log.Error("check limit fail")227 return false228 }229 role, success := claims["r"]230 if !success {231 log.Error("role no match", "role", role, "ok", success)232 return false233 }234 if roleLimit == "d" || roleLimit == "a" {235 if role != roleLimit {236 log.Error("role no auth", "role", role, "roleLimit", roleLimit)237 return false238 }239 } else {240 if role == "u" || role == "d" {241 } else {242 log.Error("role no exist", "role", role)243 return false244 }245 }246 } else {247 log.Error("token invalid")248 return false249 }250 return true251}252func checkLimit(tokenString string, limit int64) bool {253 db := *ethdb.ChainDb254 tokenHash := util.EthHash([]byte(tokenString))255 has, err := db.Has(tokenHash.Bytes())256 if err != nil {257 log.Error("db has", "err", err)258 return false259 }260 currentBlockNum := public.BC.CurrentBlock().Number()261 if !has {262 expiredBlockNum := big.NewInt(0).Add(big.NewInt(limit), currentBlockNum)263 err = db.Put(tokenHash.Bytes(), expiredBlockNum.Bytes())264 if err != nil {265 log.Error("db put tokenHash", "err", err)266 return false267 }268 } else {...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...174 returnString = strings.Trim(returnString, ",")175 return returnString, nil176}177func typeString(token ast.Expr, typeMap map[string]string) (string, error) {178 tokenString := ""179 switch t := token.(type) {180 case *ast.SelectorExpr:181 name, err := typeString(t.X, typeMap)182 if err != nil {183 return tokenString, err184 }185 tokenString += name + "." + t.Sel.String()186 case *ast.Ident:187 if token, has := typeMap[t.String()]; has {188 tokenString += token189 } else {190 tokenString += t.String()191 }192 case *ast.StarExpr:193 name, err := typeString(t.X, typeMap)194 if err != nil {195 return tokenString, err196 }197 tokenString += "*" + name198 case *ast.ArrayType:199 name, err := typeString(t.Elt, typeMap)200 if err != nil {201 return tokenString, err202 }203 tokenString += "[]" + name204 case *ast.InterfaceType:205 tokenString += "interface{}"206 case *ast.ChanType:207 name, err := typeString(t.Value, typeMap)208 if err != nil {209 return tokenString, err210 }211 tokenString += "chan " + name212 case *ast.MapType:213 keyString, err := typeString(t.Key, typeMap)214 if err != nil {215 return tokenString, err216 }217 valueString, err := typeString(t.Value, typeMap)218 if err != nil {219 return tokenString, err220 }221 tokenString += "map[" + keyString + "]" + valueString222 default:223 return "", errors.New("unexpect types")224 }225 return tokenString, nil226}227func collectAPIFile(dir string) (*token.FileSet, map[string]*ast.Package, error) {228 files, err := ioutil.ReadDir(dir)229 if err != nil {230 return nil, nil, err231 }232 fset := token.NewFileSet()233 pkgs := make(map[string]*ast.Package)234 for _, f := range files {235 subDirPath := path.Join(dir, f.Name())236 subModuleFiles, err := ioutil.ReadDir(subDirPath)237 if err != nil {238 return nil, nil, err239 }...

Full Screen

Full Screen

lexer.go

Source:lexer.go Github

copy

Full Screen

...39func (l *Lexer) Tokenize() []types.Token {40 inTag := false41 lineNo := 142 var result []types.Token43 for _, tokenString := range utility.SmartSplitWithRegex(l.r, l.template, -1) {44 if tokenString != "" {45 result = append(result, l.createToken(tokenString, lineNo, inTag))46 lineNo += strings.Count(tokenString, "\n")47 }48 inTag = !inTag49 }50 return result51}52func (l *Lexer) createToken(tokenString string, lineNo int, inTag bool) types.Token {53 if inTag {54 tokenStart := tokenString[0:2]55 if tokenStart == BLOCK_TAG_START {56 content := strings.TrimSpace(tokenString[2 : len(tokenString)-2])57 if l.verbatim {58 if content != l.verbatimBlock {59 return types.Token{60 TokenType: types.TOKEN_TEXT,61 Content: tokenString,62 LineNo: lineNo,63 }64 }65 l.verbatim = false66 } else if content[:8] == "verbatim" {67 l.verbatim = true68 l.verbatimBlock = fmt.Sprintf("end%s", content)69 }70 return types.Token{71 TokenType: types.TOKEN_BLOCK,72 Content: content,73 LineNo: lineNo,74 }75 }76 if l.verbatim == false {77 content := strings.TrimSpace(tokenString[2 : len(tokenString)-2])78 if tokenStart == VARIABLE_TAG_START {79 return types.Token{80 TokenType: types.TOKEN_VAR,81 Content: content,82 LineNo: lineNo,83 }84 }85 if tokenStart == COMMENT_TAG_START {86 return types.Token{87 TokenType: types.TOKEN_COMMENT,88 Content: content,89 LineNo: lineNo,90 }91 }92 }93 }94 return types.Token{95 TokenType: types.TOKEN_TEXT,96 Content: tokenString,97 LineNo: lineNo,98 }99}...

Full Screen

Full Screen

tokenString

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v := validation.Validation{}4 v.Required("foo", "foo").Message("foo is required")5 v.MinSize("foo", 6, "foo").Message("foo min size is 6")6 v.MaxSize("foo", 10, "foo").Message("foo max size is 10")7 v.Range("foo", 6, 10, "foo").Message("foo size must between 6 and 10")8 v.Email("foo", "foo").Message("foo must be a valid email")9 v.Mobile("foo", "foo").Message("foo must be a valid mobile")10 v.Phone("foo", "foo").Message("foo must be a valid phone")11 v.Tel("foo", "foo").Message("foo must be a valid tel")12 v.IP("foo", "foo").Message("foo must be a valid ip")13 v.Base64("foo", "foo").Message("foo must be a valid base64")14 v.Domain("foo", "foo").Message("foo must be a valid domain")15 v.IPv4("foo", "foo").Message("foo must be a valid ipv4")16 v.IPv6("foo", "foo").Message("foo must be a valid ipv6")17 v.Alpha("foo", "foo").Message("foo must be a valid alpha")18 v.Numeric("foo", "foo").Message("foo must be a valid numeric")19 v.AlphaNumeric("foo", "foo").Message("foo must be a valid alphaNumeric")20 v.Match("foo", "foo", "foo").Message("foo must be a valid match")21 v.NoMatch("foo", "foo", "foo").Message("foo must be a valid noMatch")22 v.AlphaDash("foo", "foo").Message("foo must be a valid alphaDash")23 v.Hexadecimal("foo", "foo").Message("foo must be a valid hexadecimal")24 v.HexColor("foo", "foo").Message("foo must be a valid hexColor")25 v.Rgb("foo", "foo").Message("foo must be a valid rgb")26 v.Rgba("foo", "foo").Message("foo must be a valid rgba")27 v.Hsl("foo", "foo").Message

Full Screen

Full Screen

tokenString

Using AI Code Generation

copy

Full Screen

1func main(){2 fmt.Println(types.TokenString)3}4func main(){5 fmt.Println(types.TokenString)6}7func main(){8 fmt.Println(types.TokenString)9}10func main(){11 fmt.Println(types.TokenString)12}13func main(){14 fmt.Println(types.TokenString)15}16func main(){17 fmt.Println(types.TokenString)18}19func main(){20 fmt.Println(types.TokenString)21}22func main(){23 fmt.Println(types.TokenString)24}25func main(){26 fmt.Println(types.TokenString)27}28func main(){29 fmt.Println(types.TokenString)30}31func main(){32 fmt.Println(types.TokenString)33}34func main(){35 fmt.Println(types.TokenString)36}37func main(){38 fmt.Println(types.TokenString)39}40func main(){

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful