okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
61c43ca
main
1- module ( albedo_oauth_test_support ). 2- export ([ get / 1 , occupy / 1 , release / 1 , identity / 0 ]). 3 4get ( Url ) -> 5_ = application : ensure_all_started ( inets ), 6case httpc : request ( get , { binary_to_list ( Url ), []}, [{ timeout , 5000 }], [{ body_format , binary }]) of 7{ ok , {{ _ , Status , _ }, _ , _ }} -> Status ; 8_ -> 0 9end . 10 11occupy ( Port ) -> 12{ ok , Socket } = gen_tcp : listen ( Port , [{ ip , { 127 , 0 , 0 , 1 }}]), 13{ ok , { _ , Bound }} = inet : sockname ( Socket ), 14{ Socket , Bound }. 15 16release ({ Socket , _ }) -> gen_tcp : close ( Socket ), nil . 17 18identity () -> 19<< Timestamp : 48 >> = <<( erlang : system_time ( millisecond )) : 48 >>, 20<< RandomA : 12 , RandomB : 62 , _ : 6 >> = crypto : strong_rand_bytes ( 10 ), 21Hex = binary : encode_hex (<< Timestamp : 48 , 7 : 4 , RandomA : 12 , 2 : 2 , RandomB : 62 >>, lowercase ), 22<< A : 8 / binary , B : 4 / binary , C : 4 / binary , D : 4 / binary , E : 12 / binary >> = Hex , 23<< A / binary , "-" , B / binary , "-" , C / binary , "-" , D / binary , "-" , E / binary >>.