How to use checkAccessLevel method of main Package

Best Syzkaller code snippet using main.checkAccessLevel

access.go

Source:access.go Github

copy

Full Screen

...25 panic(fmt.Sprintf("bad access level %v", access))26 }27}28var ErrAccess = errors.New("unauthorized")29func checkAccessLevel(c context.Context, r *http.Request, level AccessLevel) error {30 if accessLevel(c, r) >= level {31 return nil32 }33 if u := user.Current(c); u != nil {34 // Log only if user is signed in. Not-signed-in users are redirected to login page.35 log.Errorf(c, "unauthorized access: %q [%q] access level %v", u.Email, u.AuthDomain, level)36 }37 return ErrAccess38}39// AuthDomain is broken in AppEngine tests.40var isBrokenAuthDomainInTest = false41func accessLevel(c context.Context, r *http.Request) AccessLevel {42 if user.IsAdmin(c) {43 switch r.FormValue("access") {44 case "public":45 return AccessPublic46 case "user":47 return AccessUser48 }49 return AccessAdmin50 }51 u := user.Current(c)52 if u == nil ||53 // Devappserver does not pass AuthDomain.54 u.AuthDomain != "gmail.com" && !isBrokenAuthDomainInTest ||55 !strings.HasSuffix(u.Email, config.AuthDomain) {56 return AccessPublic57 }58 return AccessUser59}60func checkTextAccess(c context.Context, r *http.Request, tag string, id int64) (*Bug, *Crash, error) {61 switch tag {62 default:63 return nil, nil, checkAccessLevel(c, r, AccessAdmin)64 case textPatch:65 return nil, nil, checkJobTextAccess(c, r, "Patch", id)66 case textLog:67 return nil, nil, checkJobTextAccess(c, r, "Log", id)68 case textError:69 return nil, nil, checkJobTextAccess(c, r, "Error", id)70 case textKernelConfig:71 // This is checked based on text namespace.72 return nil, nil, nil73 case textCrashLog:74 // Log and Report can be attached to a Crash or Job.75 bug, crash, err := checkCrashTextAccess(c, r, "Log", id)76 if err == nil || err == ErrAccess {77 return bug, crash, err78 }79 return nil, nil, checkJobTextAccess(c, r, "CrashLog", id)80 case textCrashReport:81 bug, crash, err := checkCrashTextAccess(c, r, "Report", id)82 if err == nil || err == ErrAccess {83 return bug, crash, err84 }85 return nil, nil, checkJobTextAccess(c, r, "CrashReport", id)86 case textReproSyz:87 return checkCrashTextAccess(c, r, "ReproSyz", id)88 case textReproC:89 return checkCrashTextAccess(c, r, "ReproC", id)90 case textMachineInfo:91 // MachineInfo is deduplicated, so we can't find the exact crash/bug.92 // But since machine info is usually the same for all bugs and is not secret,93 // it's fine to check based on the namespace.94 return nil, nil, nil95 }96}97func checkCrashTextAccess(c context.Context, r *http.Request, field string, id int64) (*Bug, *Crash, error) {98 var crashes []*Crash99 keys, err := db.NewQuery("Crash").100 Filter(field+"=", id).101 GetAll(c, &crashes)102 if err != nil {103 return nil, nil, fmt.Errorf("failed to query crashes: %v", err)104 }105 if len(crashes) != 1 {106 err := fmt.Errorf("checkCrashTextAccess: found %v crashes for %v=%v", len(crashes), field, id)107 if len(crashes) == 0 {108 err = fmt.Errorf("%v: %w", err, ErrClientNotFound)109 }110 return nil, nil, err111 }112 crash := crashes[0]113 bug := new(Bug)114 if err := db.Get(c, keys[0].Parent(), bug); err != nil {115 return nil, nil, fmt.Errorf("failed to get bug: %v", err)116 }117 bugLevel := bug.sanitizeAccess(accessLevel(c, r))118 return bug, crash, checkAccessLevel(c, r, bugLevel)119}120func checkJobTextAccess(c context.Context, r *http.Request, field string, id int64) error {121 keys, err := db.NewQuery("Job").122 Filter(field+"=", id).123 KeysOnly().124 GetAll(c, nil)125 if err != nil {126 return fmt.Errorf("failed to query jobs: %v", err)127 }128 if len(keys) != 1 {129 err := fmt.Errorf("checkJobTextAccess: found %v jobs for %v=%v", len(keys), field, id)130 if len(keys) == 0 {131 // This can be triggered by bad user requests, so don't log the error.132 err = fmt.Errorf("%v: %w", err, ErrClientNotFound)133 }134 return err135 }136 bug := new(Bug)137 if err := db.Get(c, keys[0].Parent(), bug); err != nil {138 return fmt.Errorf("failed to get bug: %v", err)139 }140 bugLevel := bug.sanitizeAccess(accessLevel(c, r))141 return checkAccessLevel(c, r, bugLevel)142}143func (bug *Bug) sanitizeAccess(currentLevel AccessLevel) AccessLevel {144 for ri := len(bug.Reporting) - 1; ri >= 0; ri-- {145 bugReporting := &bug.Reporting[ri]146 if ri == 0 || !bugReporting.Reported.IsZero() {147 ns := config.Namespaces[bug.Namespace]148 bugLevel := ns.ReportingByName(bugReporting.Name).AccessLevel149 if currentLevel < bugLevel {150 if bug.Status == BugStatusInvalid ||151 bug.Status == BugStatusFixed || len(bug.Commits) != 0 {152 // Invalid and fixed bugs are visible in all reportings,153 // however, without previous reporting private information.154 lastLevel := ns.Reporting[len(ns.Reporting)-1].AccessLevel155 if currentLevel >= lastLevel {...

Full Screen

Full Screen

checkAccessLevel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(checkAccessLevel(1))4 fmt.Println(checkAccessLevel(2))5 fmt.Println(checkAccessLevel(3))6 fmt.Println(checkAccessLevel(4))7}

Full Screen

Full Screen

checkAccessLevel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(checkAccessLevel(0))4 fmt.Println(checkAccessLevel(1))5 fmt.Println(checkAccessLevel(2))6 fmt.Println(checkAccessLevel(3))

Full Screen

Full Screen

checkAccessLevel

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Access Level: ", checkAccessLevel(5))4}5import (6func checkAccessLevel(level int) string {7 if level > 5 {8 } else if level > 3 {9 } else {10 }11}

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 Syzkaller 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