How to use KeySystem method of html Package

Best K6 code snippet using html.KeySystem

elements_gen_test.go

Source:elements_gen_test.go Github

copy

Full Screen

1/*2 *3 * k6 - a next-generation load testing tool4 * Copyright (C) 2019 Load Impact5 *6 * This program is free software: you can redistribute it and/or modify7 * it under the terms of the GNU Affero General Public License as8 * published by the Free Software Foundation, either version 3 of the9 * License, or (at your option) any later version.10 *11 * This program is distributed in the hope that it will be useful,12 * but WITHOUT ANY WARRANTY; without even the implied warranty of13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14 * GNU Affero General Public License for more details.15 *16 * You should have received a copy of the GNU Affero General Public License17 * along with this program. If not, see <http://www.gnu.org/licenses/>.18 *19 */20package html21import (22 "context"23 "testing"24 "github.com/dop251/goja"25 "github.com/stretchr/testify/assert"26 "github.com/loadimpact/k6/js/common"27)28var textTests = []struct {29 id string30 property string31 data string32}{33 {"a1", "download", "file:///path/name"},34 {"a1", "referrerPolicy", "no-referrer"},35 {"a1", "href", "http://test.url"},36 {"a1", "target", "__blank"},37 {"a1", "type", "text/html"},38 {"a1", "accessKey", "w"},39 {"a1", "hrefLang", "es"},40 {"a1", "toString", "http://test.url"},41 {"a2", "referrerPolicy", ""},42 {"a2", "accessKey", ""},43 {"audio1", "src", "foo.wav"},44 {"audio1", "crossOrigin", "anonymous"},45 {"audio1", "currentSrc", "foo.wav"},46 {"audio1", "mediaGroup", "testgroup"},47 {"base1", "href", "foo.html"},48 {"base1", "target", "__any"},49 {"btn1", "accessKey", "e"},50 {"btn1", "type", "button"},51 {"btn2", "type", "submit"},52 {"btn3", "type", "submit"},53 {"data1", "value", "121"},54 {"data2", "value", ""},55 {"embed1", "type", "video/avi"},56 {"embed1", "src", "movie.avi"},57 {"embed1", "width", "640"},58 {"embed1", "height", "480"},59 {"fset1", "name", "fset1_name"},60 {"form1", "target", "__self"},61 {"form1", "action", "submit_url"},62 {"form1", "enctype", "text/plain"},63 {"form1", "encoding", "text/plain"},64 {"form1", "acceptCharset", "ISO-8859-1"},65 {"form1", "target", "__self"},66 {"form1", "autocomplete", "off"},67 {"form2", "enctype", "application/x-www-form-urlencoded"},68 {"form2", "autocomplete", "on"},69 {"iframe1", "referrerPolicy", "no-referrer"},70 {"iframe2", "referrerPolicy", ""},71 {"iframe3", "referrerPolicy", ""},72 {"iframe1", "width", "640"},73 {"iframe1", "height", "480"},74 {"iframe1", "name", "frame_name"},75 {"iframe1", "src", "testframe.html"},76 {"img1", "src", "test.png"},77 {"img1", "currentSrc", "test.png"},78 {"img1", "sizes", "100vw,50vw"},79 {"img1", "srcset", "large.jpg 1024w,medium.jpg 640w"},80 {"img1", "alt", "alt text"},81 {"img1", "crossOrigin", "anonymous"},82 {"img1", "name", "img_name"},83 {"img1", "useMap", "#map_name"},84 {"img1", "referrerPolicy", "origin"},85 {"img2", "crossOrigin", "use-credentials"},86 {"img2", "referrerPolicy", ""},87 {"img3", "referrerPolicy", ""},88 {"input1", "name", "input1_name"},89 {"input1", "type", "button"},90 {"input1", "value", "input1-val"},91 {"input1", "defaultValue", "input1-val"},92 {"input2", "type", "text"},93 {"input2", "value", ""},94 {"input5", "alt", "input_img"},95 {"input5", "src", "input.png"},96 {"input5", "width", "80"},97 {"input5", "height", "40"},98 {"input6", "accept", ".jpg,.png"},99 {"input7", "autocomplete", "off"},100 {"input7", "pattern", "..."},101 {"input7", "placeholder", "help text"},102 {"input7", "min", "2017-01-01"},103 {"input7", "max", "2017-12-12"},104 {"input7", "dirName", "input7.dir"},105 {"input7", "accessKey", "s"},106 {"input7", "step", "0.1"},107 {"kg1", "challenge", "cx1"},108 {"kg1", "keytype", "DSA"},109 {"kg1", "name", "kg1_name"},110 {"kg2", "challenge", ""},111 {"kg2", "keytype", "RSA"},112 {"kg2", "type", "keygen"},113 {"label1", "htmlFor", "input1_name"},114 {"legend1", "accessKey", "l"},115 {"li1", "type", "disc"},116 {"li2", "type", ""},117 {"link1", "crossOrigin", "use-credentials"},118 {"link1", "referrerPolicy", "no-referrer"},119 {"link1", "href", "test.css"},120 {"link1", "hreflang", "pl"},121 {"link1", "media", "print"},122 {"link1", "rel", "alternate author"},123 {"link1", "target", "__self"},124 {"link1", "type", "stylesheet"},125 {"link2", "referrerPolicy", ""},126 {"map1", "name", "map1_name"},127 {"meta1", "name", "author"},128 {"meta1", "content", "author name"},129 {"meta2", "httpEquiv", "refresh"},130 {"meta2", "content", "1;www.test.com"},131 {"meta2", "content", "1;www.test.com"},132 {"ins1", "cite", "cite.html"},133 {"ins1", "datetime", "2017-01-01"},134 {"object1", "data", "test.png"},135 {"object1", "type", "image/png"},136 {"object1", "name", "obj1_name"},137 {"object1", "width", "150"},138 {"object1", "height", "75"},139 {"object1", "useMap", "#map1_name"},140 {"ol1", "type", "a"},141 {"optgroup1", "label", "optlabel"},142 {"out1", "htmlFor", "input1"},143 {"out1", "name", "out1_name"},144 {"out1", "type", "output"},145 {"par1", "name", "param1_name"},146 {"par1", "value", "param1_val"},147 {"pre1", "name", "pre1_name"},148 {"pre1", "value", "pre1_val"},149 {"quote1", "cite", "http://cite.com/url"},150 {"script1", "crossOrigin", "use-credentials"},151 {"script1", "type", "text/javascript"},152 {"script1", "src", "script.js"},153 {"script1", "charset", "ISO-8859-1"},154 {"select1", "name", "sel1_name"},155 {"src1", "keySystem", "keysys"},156 {"src1", "media", "(min-width: 600px)"},157 {"src1", "sizes", "100vw,50vw"},158 {"src1", "srcset", "large.jpg 1024w,medium.jpg 640w"},159 {"src1", "src", "test.png"},160 {"src1", "type", "image/png"},161 {"td1", "headers", "th1"},162 {"th1", "abbr", "hdr"},163 {"th1", "scope", "row"},164 {"txtarea1", "accessKey", "k"},165 {"txtarea1", "autocomplete", "off"},166 {"txtarea1", "autocapitalize", "words"},167 {"txtarea1", "wrap", "hard"},168 {"txtarea2", "autocomplete", "on"},169 {"txtarea2", "autocapitalize", "sentences"},170 {"txtarea2", "wrap", "soft"},171 {"track1", "kind", "metadata"},172 {"track1", "src", "foo.en.vtt"},173 {"track1", "label", "English"},174 {"track1", "srclang", "en"},175 {"track2", "kind", "subtitle"},176 {"track2", "src", "foo.sv.vtt"},177 {"track2", "srclang", "sv"},178 {"track2", "label", "Svenska"},179 {"time1", "datetime", "2017-01-01"},180 {"ul1", "type", "circle"},181}182var intTests = []struct {183 id string184 property string185 data int186}{187 {"img1", "width", 100},188 {"img1", "height", 50},189 {"input7", "maxLength", 10},190 {"input7", "size", 5},191 {"li1", "value", 0},192 {"li2", "value", 10},193 {"meter1", "min", 90},194 {"meter1", "max", 110},195 {"meter1", "low", 95},196 {"meter1", "high", 105},197 {"meter1", "optimum", 100},198 {"object1", "tabIndex", 6},199 {"ol1", "start", 1},200 {"td1", "colSpan", 2},201 {"td1", "rowSpan", 3},202 {"th1", "colSpan", 1},203 {"th1", "colSpan", 1},204 {"txtarea1", "rows", 10},205 {"txtarea1", "cols", 12},206 {"txtarea1", "maxLength", 128},207 {"txtarea1", "tabIndex", 4},208}209var boolTests = []struct {210 idTrue string211 idFalse string212 property string213}{214 {"audio1", "audio2", "autoplay"},215 {"audio1", "audio2", "controls"},216 {"audio1", "audio2", "loop"},217 {"audio1", "audio2", "muted"},218 {"audio1", "audio2", "defaultMuted"},219 {"btn1", "btn2", "autofocus"},220 {"btn1", "btn2", "disabled"},221 {"fset1", "fset2", "disabled"},222 {"form1", "form2", "noValidate"},223 {"iframe1", "iframe2", "allowfullscreen"},224 {"img1", "img2", "isMap"},225 {"input1", "input2", "disabled"},226 {"input1", "input2", "autofocus"},227 {"input1", "input2", "required"},228 {"input3", "input4", "checked"},229 {"input3", "input4", "defaultChecked"},230 {"input7", "input1", "readonly"},231 {"input3", "input4", "multiple"},232 {"kg1", "kg2", "autofocus"},233 {"kg1", "kg2", "disabled"},234 {"object1", "object2", "typeMustMatch"},235 {"ol1", "ol2", "reversed"},236 {"optgroup1", "optgroup2", "disabled"},237 {"opt1", "opt2", "selected"},238 {"opt1", "opt2", "defaultSelected"},239 {"script1", "script2", "async"},240 {"script1", "script2", "defer"},241 {"script1", "script2", "noModule"},242 {"select1", "select2", "autofocus"},243 {"select1", "select2", "disabled"},244 {"select1", "select2", "multiple"},245 {"select1", "select2", "required"},246 {"table1", "table2", "sortable"},247 {"th1", "th2", "sorted"},248 {"txtarea1", "txtarea2", "readOnly"},249 {"txtarea1", "txtarea2", "required"},250}251var nullTests = []struct {252 id string253 property string254}{255 {"audio2", "crossOrigin"},256 {"img3", "crossOrigin"},257 {"link2", "crossOrigin"},258}259var urlTests = []struct {260 id string261 property string262 baseUrl string263 data string264}{265 {"a2", "href", "http://example.com/testpath", ""},266 {"a3", "href", "http://example.com", "http://example.com/relpath"},267 {"a3", "href", "http://example.com/somepath", "http://example.com/relpath"},268 {"a3", "href", "http://example.com/subdir/", "http://example.com/subdir/relpath"},269 {"a4", "href", "http://example.com/", "http://example.com/abspath"},270 {"a4", "href", "http://example.com/subdir/", "http://example.com/abspath"},271 {"a5", "href", "http://example.com/path?a=no-a&c=no-c", "http://example.com/path?a=yes-a&b=yes-b"},272 {"a6", "href", "http://example.com/path#oldfrag", "http://example.com/path#testfrag"},273 {"a7", "href", "http://example.com/prevdir/prevpath", "http://example.com/prtpath"},274 {"a8", "href", "http://example.com/testpath", "http://example.com/testpath"},275 {"base1", "href", "http://example.com", "http://example.com/foo.html"},276 {"base2", "href", "http://example.com", "http://example.com"},277 {"base3", "href", "http://example.com", "http://example.com"},278 {"audio1", "src", "http://example.com", "http://example.com/foo.wav"},279 {"audio2", "src", "http://example.com", ""},280 {"audio3", "src", "http://example.com", "http://example.com"},281 {"form1", "action", "http://example.com/", "http://example.com/submit_url"},282 {"form2", "action", "http://example.com/", ""},283 {"form3", "action", "http://example.com/", "http://example.com/"},284 {"iframe1", "src", "http://example.com", "http://example.com/testframe.html"},285 {"iframe2", "src", "http://example.com", ""},286 {"iframe3", "src", "http://example.com", "http://example.com"},287 {"img1", "src", "http://example.com", "http://example.com/test.png"},288 {"img2", "src", "http://example.com", ""},289 {"img3", "src", "http://example.com", "http://example.com"},290 {"input5", "src", "http://example.com", "http://example.com/input.png"},291 {"input5b", "src", "http://example.com", ""},292 {"input5c", "src", "http://example.com", "http://example.com"},293 {"link1", "href", "http://example.com", "http://example.com/test.css"},294 {"link2", "href", "http://example.com", ""},295 {"link3", "href", "http://example.com", "http://example.com"},296 {"object1", "data", "http://example.com", "http://example.com/test.png"},297 {"object2", "data", "http://example.com", ""},298 {"object3", "data", "http://example.com", "http://example.com"},299 {"script1", "src", "http://example.com", "http://example.com/script.js"},300 {"script2", "src", "http://example.com", ""},301 {"script3", "src", "http://example.com", "http://example.com"},302 {"src1", "src", "http://example.com", "http://example.com/test.png"},303 {"src2", "src", "http://example.com", ""},304 {"src3", "src", "http://example.com", "http://example.com"},305 {"track1", "src", "http://example.com", "http://example.com/foo.en.vtt"},306 {"track3", "src", "http://example.com", ""},307 {"track4", "src", "http://example.com", "http://example.com"},308}309const testGenElems = `<html><body>310 <a id="a1" download="file:///path/name" referrerpolicy="no-referrer" rel="open" href="http://test.url" target="__blank" type="text/html" accesskey="w" hreflang="es"></a>311 <a id="a2"></a>312 <a id="a3" href="relpath"></a>313 <a id="a4" href="/abspath"></a>314 <a id="a5" href="?a=yes-a&b=yes-b"></a>315 <a id="a6" href="#testfrag"></a>316 <a id="a7" href="../prtpath"></a>317 <a id="a8" href=""></a>318 <audio id="audio1" autoplay controls loop muted src="foo.wav" crossorigin="anonymous" mediagroup="testgroup"></audio>319 <audio id="audio2"></audio>320 <audio id="audio3" src=""></audio>321 <base id="base1" href="foo.html" target="__any"></base>322 <base id="base2"></base>323 <base id="base3" href="" target="__any"></base>324 <button id="btn1" accesskey="e" target="__any" autofocus disabled type="button"></button>325 <button id="btn2"></button>326 <button id="btn3" type="invalid_uses_default"></button> <button id="btn3" type="invalid_uses_default"></button>327 <ul><li><data id="data1" value="121"></data></li><li><data id="data2"></data></li></ul>328 <embed id="embed1" type="video/avi" src="movie.avi" width="640" height="480">329 <fieldset id="fset1" disabled name="fset1_name"></fieldset>330 <fieldset id="fset2"></fieldset>331 <form id="form1" name="form1_name" target="__self" enctype="text/plain" action="submit_url" accept-charset="ISO-8859-1" autocomplete="off" novalidate></form>332 <form id="form2"></form>333 <form id="form3" action=""></form>334 <iframe id="iframe1" allowfullscreen referrerpolicy="no-referrer" name="frame_name" width="640" height="480" src="testframe.html"></iframe>335 <iframe id="iframe2" referrerpolicy="use-default-when-invalid"></iframe>336 <iframe id="iframe3" src=""></iframe>337 <img id="img1" src="test.png" sizes="100vw,50vw" srcset="large.jpg 1024w,medium.jpg 640w" alt="alt text" crossorigin="anonymous" height="50" width="100" ismap name="img_name" usemap="#map_name" referrerpolicy="origin"/>338 <img id="img2" crossorigin="use-credentials" referrerpolicy="use-default-when-invalid"/>339 <img id="img3" src=""/>340 <input id="input1" name="input1_name" disabled autofocus required value="input1-val" type="button"/>341 <input id="input2"/>342 <input id="input3" type="checkbox" checked multiple/>343 <input id="input4" type="checkbox"/>344 <input id="input5" type="image" alt="input_img" src="input.png" width="80" height="40"/>345 <input id="input5b" type="image" />346 <input id="input5c" type="image" src=""/>347 <input id="input6" type="file" accept=".jpg,.png"/>348 <input id="input7" type="text" autocomplete="off" maxlength="10" size="5" pattern="..." placeholder="help text" readonly min="2017-01-01" max="2017-12-12" dirname="input7.dir" accesskey="s" step="0.1"/>349 <keygen id="kg1" autofocus challenge="cx1" disabled keytype="DSA" name="kg1_name"/>350 <keygen id="kg2"/>351 <label id="label1" for="input1_name"/>352 <legend id="legend1" accesskey="l"/>353 <li id="li1" type="disc"></li> <li id="li2" value="10" type=""></li>354 <link id="link1" crossorigin="use-credentials" referrerpolicy="no-referrer" href="test.css" hreflang="pl" media="print" rel="alternate author" target="__self" type="stylesheet"/>355 <link id="link2"/>356 <link id="link3" href=""/>357 <map id="map1" name="map1_name"></map>358 <meta id="meta1" name="author" content="author name" />359 <meta id="meta2" http-equiv="refresh" content="1;www.test.com" />360 <meter id="meter1" min="90" max="110" low="95" high="105" optimum="100"/>361 <ins id="ins1" cite="cite.html" datetime="2017-01-01"/>362 <object id="object1" name="obj1_name" data="test.png" type="image/png" width="150" height="75" tabindex="6" typemustmatch usemap="#map1_name"/>363 <object id="object2"/>364 <object id="object3" data=""/>365 <ol id="ol1" reversed start="1" type="a"></ol> <ol id="ol2"></ol>366 <optgroup id="optgroup1" disabled label="optlabel"></optgroup>367 <optgroup id="optgroup2"></optgroup>368 <option id="opt1" selected/><option id="opt2" />369 <output id="out1" for="input1" name="out1_name"/>370 <param id="par1" name="param1_name" value="param1_val"/>371 <pre id="pre1" name="pre1_name" value="pre1_val"/>372 <quote id="quote1" cite="http://cite.com/url"/>373 <script id="script1" crossorigin="use-credentials" type="text/javascript" src="script.js" charset="ISO-8859-1" defer async nomodule></script>374 <script id="script2"></script>375 <script id="script3" src=""></script>376 <select id="select1" name="sel1_name" autofocus disabled multiple required></select>377 <select id="select2"></select>378 <source id="src1" keysystem="keysys" media="(min-width: 600px)" sizes="100vw,50vw" srcset="large.jpg 1024w,medium.jpg 640w" src="test.png" type="image/png"></source>379 <source id="src2"></source>380 <source id="src3" src=""></source>381 <style id="style1" media="print"></style>382 <table id="table1" sortable><tr><td id="td1" colspan="2" rowspan="3" headers="th1"></th><th id="th1" abbr="hdr" scope="row" sorted>Header</th><th id="th2"></th></tr></table>383 <table id="table2"></table>384 <textarea id="txtarea1" value="init_txt" placeholder="display_txt" rows="10" cols="12" maxlength="128" accesskey="k" tabIndex="4" readonly required autocomplete="off" autocapitalize="words" wrap="hard"></textarea>385 <textarea id="txtarea2"></textarea>386 <time id="time1" datetime="2017-01-01"/>387 <track id="track1" kind="metadata" src="foo.en.vtt" srclang="en" label="English"></track>388 <track id="track2" src="foo.sv.vtt" srclang="sv" label="Svenska"></track>389 <track id="track3"></track>390 <track id="track4" src=""></track>391 <ul id="ul1" type="circle"/>392 `393func TestGenElements(t *testing.T) {394 rt := goja.New()395 rt.SetFieldNameMapper(common.FieldNameMapper{})396 ctx := common.WithRuntime(context.Background(), rt)397 rt.Set("src", testGenElems)398 rt.Set("html", common.Bind(rt, &HTML{}, &ctx))399 _, err := common.RunString(rt, "var doc = html.parseHTML(src)")400 assert.NoError(t, err)401 assert.IsType(t, Selection{}, rt.Get("doc").Export())402 t.Run("Test text properties", func(t *testing.T) {403 for _, test := range textTests {404 v, err := common.RunString(rt, `doc.find("#`+test.id+`").get(0).`+test.property+`()`)405 if err != nil {406 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v ", test.id, test.property, err)407 } else if v.Export() != test.data {408 t.Errorf("Expected '%s' for property name '%s' element id '#%s'. Got '%s'", test.data, test.property, test.id, v.String())409 }410 }411 })412 t.Run("Test bool properties", func(t *testing.T) {413 for _, test := range boolTests {414 vT, errT := common.RunString(rt, `doc.find("#`+test.idTrue+`").get(0).`+test.property+`()`)415 if errT != nil {416 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.idTrue, errT)417 } else if vT.Export() != true { // nolint: gosimple418 t.Errorf("Expected true for property name '%s' on element id '#%s'", test.property, test.idTrue)419 }420 vF, errF := common.RunString(rt, `doc.find("#`+test.idFalse+`").get(0).`+test.property+`()`)421 if errF != nil {422 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.idFalse, errF)423 } else if vF.Export() != false { // nolint: gosimple424 t.Errorf("Expected false for property name '%s' on element id '#%s'", test.property, test.idFalse)425 }426 }427 })428 t.Run("Test int64 properties", func(t *testing.T) {429 for _, test := range intTests {430 v, err := common.RunString(rt, `doc.find("#`+test.id+`").get(0).`+test.property+`()`)431 if err != nil {432 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.id, err)433 } else if v.Export() != int64(test.data) {434 t.Errorf("Expected %d for property name '%s' on element id '#%s'. Got %d", test.data, test.property, test.id, v.ToInteger())435 }436 }437 })438 t.Run("Test nullable properties", func(t *testing.T) {439 for _, test := range nullTests {440 v, err := common.RunString(rt, `doc.find("#`+test.id+`").get(0).`+test.property+`()`)441 if err != nil {442 t.Errorf("Error for property name '%s' on element id '#%s':\n%+v", test.property, test.id, err)443 } else if v.Export() != nil {444 t.Errorf("Expected null for property name '%s' on element id '#%s'", test.property, test.id)445 }446 }447 })448 t.Run("Test url properties", func(t *testing.T) {449 html := HTML{}450 sel, parseError := html.ParseHTML(ctx, testGenElems)451 if parseError != nil {452 t.Errorf("Unable to parse html")453 }454 for _, test := range urlTests {455 sel.URL = test.baseUrl456 rt.Set("urldoc", sel)457 v, err := common.RunString(rt, `urldoc.find("#`+test.id+`").get(0).`+test.property+`()`)458 if err != nil {459 t.Errorf("Error for url property '%s' on element id '#%s':\n%+v", test.property, test.id, err)460 } else if v.Export() != test.data {461 t.Errorf("Expected '%s' for property name '%s' on element id '#%s', got '%s'", test.data, test.property, test.id, v.String())462 }463 }464 })465}...

Full Screen

Full Screen

kazi.go

Source:kazi.go Github

copy

Full Screen

1package main2import (3 "crypto/rand"4 "html/template"5 "log"6 "net/http"7 "os"8 "time"9 uuid "github.com/nu7hatch/gouuid"10 "strings"11 "fmt"12 "io"13 "encoding/hex"14 "golang.org/x/crypto/nacl/secretbox"15 "google.golang.org/appengine"16 "google.golang.org/appengine/memcache"17)18type msgAndSecretKeys struct {19 MsgKey string20 SecretKey string21 URLMsg string22}23var tpl *template.Template24func main() {25 tpl = template.Must(template.ParseGlob("./*.html"))26 http.HandleFunc("/", index)27 http.HandleFunc("/msg/", message)28 port := os.Getenv("PORT")29 if port == "" {30 port = "8080"31 log.Printf("Defaulting to port %s", port)32 }33 log.Printf("Listening on port %s", port)34 log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))35}36// create a message37func index(w http.ResponseWriter, r *http.Request) {38 ctx := appengine.NewContext(r)39 var keySystem msgAndSecretKeys40 if r.Method == http.MethodPost {41 msg := r.FormValue("umsg")42 mkey, _ := uuid.NewV4()43 skey := generatePassword()44 encryptedMessage := encrypt(msg, skey)45 keySystem.MsgKey = mkey.String()46 keySystem.SecretKey = fmt.Sprintf("%x", skey)47 keySystem.URLMsg = "/msg/" + keySystem.MsgKey48 // store message in memcache49 item := &memcache.Item{50 Key: keySystem.MsgKey,51 Value: []byte(encryptedMessage),52 }53 err := memcache.Add(ctx, item)54 if err != nil {55 http.Error(w, err.Error(), http.StatusInternalServerError)56 return57 }58 err = tpl.ExecuteTemplate(w, "secret.html", keySystem)59 if err != nil {60 http.Error(w, err.Error(), http.StatusInternalServerError)61 return62 }63 } else {64 err := tpl.ExecuteTemplate(w, "index.html", nil)65 if err != nil {66 http.Error(w, err.Error(), http.StatusInternalServerError)67 return68 }69 }70}71// return a message based on its id72func message(w http.ResponseWriter, r *http.Request) {73 ctx := appengine.NewContext(r)74 // extracting key from url75 key := strings.SplitN(r.URL.Path, "/", 3)[2]76 // extracting item from google appengine memcache77 item, err := memcache.Get(ctx, key)78 if err != nil {79 http.NotFound(w, r)80 return81 }82 var password [32]byte83 bs, err := hex.DecodeString(r.FormValue("secret"))84 if err != nil || len(bs) != 32 {85 http.Error(w, err.Error(), 500)86 return87 }88 copy(password[:], bs)89 decryptedMessage, err := decrypt(string(item.Value), password)90 if err != nil {91 http.NotFound(w, r)92 return93 }94 // memcache.Delete(ctx, key), use this for super duper tight security, message is burned the second its opened95 // this one below for specified seconds expiration, will destroy message after some time96 if item.Flags == 0 {97 item.Expiration = 30 * time.Second98 item.Flags = 199 memcache.Set(ctx, item)100 }101 err = tpl.ExecuteTemplate(w, "message.html", decryptedMessage)102 if err != nil {103 http.Error(w, err.Error(), http.StatusInternalServerError)104 return105 }106}107func decrypt(encrypted string, password [32]byte) (string, error) {108 var nonce [24]byte109 parts := strings.SplitN(encrypted, ":", 2)110 if len(parts) < 2 {111 return "", fmt.Errorf("Expected nonce")112 }113 bs, err := hex.DecodeString(parts[0])114 if err != nil || len(bs) != 24 {115 return "", fmt.Errorf("invalid nonce")116 }117 copy(nonce[:], bs)118 bs, err = hex.DecodeString(parts[1])119 if err != nil {120 return "", fmt.Errorf("invalid message")121 }122 decrypted, ok := secretbox.Open(nil, bs, &nonce, &password)123 if !ok {124 return "", fmt.Errorf("invalid message")125 }126 return string(decrypted), nil127}128func encrypt(decrypted string, password [32]byte) string {129 var nonce [24]byte130 io.ReadAtLeast(rand.Reader, nonce[:], 24)131 encrypted := secretbox.Seal(nil, []byte(decrypted), &nonce, &password)132 return fmt.Sprintf("%x:%x", nonce[:], encrypted)133}134func generatePassword() [32]byte {135 var password [32]byte136 io.ReadAtLeast(rand.Reader, password[:], 32)137 return password138}...

Full Screen

Full Screen

keys.go

Source:keys.go Github

copy

Full Screen

...57 KeySocket = "socket"58 KeySQL = "sql"59 KeyStatus = "status"60 KeySvc = "svc"61 KeySystem = "system"62 KeyTest = "test"63 KeyTitle = "title"64 KeyUser = "user"65 KeyVoyager = "voyager"66)67// Pluralizes a string68func Plural(s string) string {69 return inflection.Plural(s)70}71// Converts a string to TitleCase72func Title(k string) string {73 if len(k) == 0 {74 return k75 }...

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 http.HandleFunc("/", handler)4 log.Fatal(http.ListenAndServe("localhost:8000", nil))5}6func handler(w http.ResponseWriter, r *http.Request) {7 fmt.Fprintf(w, "URL.Path = %q\n", html.EscapeString(r.URL.Path))8}

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("This is <b>HTML</b>"))4}5import (6func main() {7 fmt.Println(html.UnescapeString("This is &lt;b&gt;HTML&lt;/b&gt;"))8}9import (10func main() {11 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)12 t.ExecuteTemplate(os.Stdout, "T", template.HTML("<script>alert('you have been pwned')</script>"))13}14import (15func main() {16 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)17 t.ExecuteTemplate(os.Stdout, "T", template.JS("<script>alert('you have been pwned')</script>"))18}19import (20func main() {21 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)22}

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("<script>alert('Hello World!')</script>"))4}5import (6func main() {7 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;Hello World!&#39;)&lt;/script&gt;"))8}9import (10func main() {11 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)12 t.ExecuteTemplate(os.Stdout, "T", template.HTML("<script>alert('you have been pwned')</script>"))13}14import (15func main() {16 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)17 t.ExecuteTemplate(os.Stdout, "T", template.JS("<script>alert('you have been pwned')</script>"))18}19import (20func main() {21 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)22}23import (

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("<script>alert('hello')</script>"))4}5import (6func main() {7 fmt.Println(html.UnescapeString("&lt;script&gt;alert(&#39;hello&#39;)&lt;/script&gt;"))8}9import (10func main() {11 fmt.Println(template.HTMLEscapeString("<script>alert('hello')</script>"))12}13import (14func main() {15 fmt.Println(template.HTMLEscape(nil, []byte("<script>alert('hello')</script>")))16}17import (18func main() {19 fmt.Println(template.HTMLEscape(nil, []byte("<script>alert('hello')</script>")))20}21import (22func main() {23 fmt.Println(template.HTML("<script>alert('hello')</script>"))24}25import (26func main() {27 fmt.Println(template.JSEscapeString("<script>alert('hello')</script>"))28}

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("<script>alert('hello')</script>"))4}5import (6func main() {7 fmt.Println(template.HTMLEscapeString("<script>alert('hello')</script>"))8}9import (10func main() {11}12import (13func main() {14 fmt.Println(url.QueryUnescape("%3A%2F%2Fgolang.org%2Fpkg%2Fnet%2Furl%2F%23QueryEscape"))15}16import (17func main() {18 fmt.Println(strings.ToLower("GOLANG"))19}20import (21func main() {22 fmt.Println(strings.ToUpper("golang"))23}24import (25func main() {26 fmt.Println(strconv.Atoi("123"))27}28import (29func main() {30 fmt.Println(strconv.Itoa(123))31}32import (33func main() {34 fmt.Println(strconv.ParseBool("true"))35}36import (37func main() {38 fmt.Println(strconv.FormatBool(true))39}40import

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2type Html struct {3}4func main() {5 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {6 if r.Method == "POST" {7 body, err := ioutil.ReadAll(r.Body)8 if err != nil {9 panic(err)10 }11 fmt.Println(string(body))12 err = json.Unmarshal(body, &html)13 if err != nil {14 panic(err)15 }16 fmt.Println(html.Address)17 fmt.Println(html.PrivateKey)18 fmt.Println(html.PublicKey)19 ks := keystore.NewKeyStore("keystore", keystore.StandardScryptN, keystore.StandardScryptP)20 account, err := ks.ImportECDSA(crypto.ToECDSAUnsafe(common.Hex2Bytes(html.PrivateKey)), html.Address)21 if err != nil {22 panic(err)23 }24 fmt.Println(account.Address.Hex())25 }26 })27 http.ListenAndServe(":9090", nil)28}29 var address = document.getElementById("address");30 var privateKey = document.getElementById("privateKey");31 var publicKey = document.getElementById("public

Full Screen

Full Screen

KeySystem

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("Hello, world!"))4}5import (6func main() {7 fmt.Println(template.HTMLEscapeString("Hello, world!"))8}9import (10func main() {11 fmt.Println(color.RGBToYCbCr(1, 1, 1))12}13import (14func main() {15 fmt.Println(draw.Over)16}17import (18func main() {19 fmt.Println(gif.DefaultQuantizer)20}21import (22func main() {23 fmt.Println(jpeg.DefaultQuality)24}25import (26func main() {27 fmt.Println(png.DefaultCompression)28}29import (30func main() {31 fmt.Println(suffixarray.DefaultMaxFuture)32}33import (34func 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 K6 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