Commit 600973bda90d3a857b3544d9a72eb7ed15c7a1fe
Committed by
gabrielamayoli
1 parent
39309d28
Exists in
master
and in
1 other branch
Atualização dos primeiros testes do primeiro controller da nova coleta.
Showing
3 changed files
with
93 additions
and
26 deletions
Show diff stats
src/Cacic/WSBundle/Controller/NeoController.php
| ... | ... | @@ -73,6 +73,7 @@ class NeoController extends Controller { |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | $session = $request->getSession(); |
| 76 | + $session->start(); | |
| 76 | 77 | |
| 77 | 78 | //Gera chave criptografada |
| 78 | 79 | $chave = "123456"; |
| ... | ... | @@ -109,6 +110,9 @@ class NeoController extends Controller { |
| 109 | 110 | return $response; |
| 110 | 111 | } |
| 111 | 112 | |
| 113 | + /* | |
| 114 | + Insere o computador se não existir | |
| 115 | + */ | |
| 112 | 116 | public function getTestAction(Request $request) |
| 113 | 117 | { |
| 114 | 118 | //1 - Verificar se computador existe |
| ... | ... | @@ -116,9 +120,14 @@ class NeoController extends Controller { |
| 116 | 120 | $status = $request->getContent(); |
| 117 | 121 | $em = $this->getDoctrine()->getManager(); |
| 118 | 122 | |
| 123 | + $logger->debug("JSON getTest:\n".$status); | |
| 124 | + | |
| 125 | + | |
| 119 | 126 | $dados = json_decode($status, true); |
| 127 | + | |
| 120 | 128 | if (empty($dados)) { |
| 121 | - // REtorna erro se o JSON for inválido | |
| 129 | + $logger->error("JSON INVÁLIDO!!!!!!!!!!!!!!!!!!! Erro no getTest"); | |
| 130 | + // Retorna erro se o JSON for inválido | |
| 122 | 131 | $error_msg = '{ |
| 123 | 132 | "message": "JSON Inválido", |
| 124 | 133 | "codigo": 1 |
| ... | ... | @@ -128,7 +137,8 @@ class NeoController extends Controller { |
| 128 | 137 | $response->setContent($error_msg); |
| 129 | 138 | return $response; |
| 130 | 139 | } |
| 131 | - $logger->debug("JSON get Test status".print_r(json_decode($status, true), true)); | |
| 140 | + | |
| 141 | + $logger->debug("JSON get Test status \n".print_r(json_decode($status, true), true)); | |
| 132 | 142 | |
| 133 | 143 | $so_json = $dados['computador']['operatingSystem']; |
| 134 | 144 | $rede_json = $dados['computador']['networkDevices']; |
| ... | ... | @@ -138,9 +148,8 @@ class NeoController extends Controller { |
| 138 | 148 | $netmask = $rede1['netmask_ipv4']; |
| 139 | 149 | |
| 140 | 150 | // Pega rede |
| 141 | - $rede = $this->getDoctrine()->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask ); | |
| 151 | + $rede = $em->getRepository('CacicCommonBundle:Rede')->getDadosRedePreColeta( $ip_computador, $netmask ); | |
| 142 | 152 | |
| 143 | - $logger->debug("1111111111111111111111111111111111111111111 ".print_r($so_json, true)); | |
| 144 | 153 | |
| 145 | 154 | $so = $em->getRepository('CacicCommonBundle:So')->createIfNotExist($so_json['nomeOs']); |
| 146 | 155 | $computador = $em->getRepository('CacicCommonBundle:Computador')->findOneBy(array( |
| ... | ... | @@ -148,7 +157,8 @@ class NeoController extends Controller { |
| 148 | 157 | 'idSo' => $so |
| 149 | 158 | )); |
| 150 | 159 | $logger->debug("$so".print_r($so, true)); |
| 151 | - $logger->debug("$computador".print_r($computador, true)); | |
| 160 | + //$logger->debug("$computador".print_r($computador, true)); | |
| 161 | + //$logger->debug("111111111111111111111111111111111111111111111111"); | |
| 152 | 162 | |
| 153 | 163 | // Regra: MAC e SO são únicos e não podem ser nulos |
| 154 | 164 | $data = new \DateTime('NOW'); //armazena data Atual |
| ... | ... | @@ -166,21 +176,8 @@ class NeoController extends Controller { |
| 166 | 176 | |
| 167 | 177 | $em->persist( $computador ); |
| 168 | 178 | |
| 169 | - | |
| 170 | 179 | } |
| 171 | 180 | |
| 172 | - /* | |
| 173 | - $computador->setDtHrUltAcesso( $data ); | |
| 174 | - $computador->setTeVersaoCacic( $te_versao_cacic ); | |
| 175 | - $computador->setTeVersaoGercols( $te_versao_gercols ); | |
| 176 | - $computador->setTeUltimoLogin( TagValueHelper::getValueFromTags( 'UserName' ,$computer_system ) ); | |
| 177 | - $computador->setTeIpComputador( TagValueHelper::getValueFromTags( 'IPAddress' ,$network_adapter ) ); | |
| 178 | - $computador->setNmComputador( TagValueHelper::getValueFromTags( 'Caption' ,$computer_system )); | |
| 179 | - $this->getEntityManager()->persist( $computador ); | |
| 180 | - | |
| 181 | - $acoes = $this->getEntityManager()->getRepository('CacicCommonBundle:Acao')->findAll(); | |
| 182 | - */ | |
| 183 | - | |
| 184 | 181 | // 2.1 - Se existir, atualiza hora de inclusão |
| 185 | 182 | else |
| 186 | 183 | { |
| ... | ... | @@ -189,7 +186,6 @@ class NeoController extends Controller { |
| 189 | 186 | //Atualiza hora de inclusão |
| 190 | 187 | $em->persist($computador); |
| 191 | 188 | |
| 192 | - | |
| 193 | 189 | } |
| 194 | 190 | |
| 195 | 191 | // 3 - Grava no log de acesso |
| ... | ... | @@ -233,20 +229,37 @@ class NeoController extends Controller { |
| 233 | 229 | $response = new JsonResponse(); |
| 234 | 230 | $response->setStatusCode('200'); |
| 235 | 231 | return $response; |
| 232 | + } | |
| 236 | 233 | |
| 234 | + /* | |
| 235 | + * ConfigTeste | |
| 236 | + */ | |
| 237 | + public function configAction(Request $request) | |
| 238 | + { | |
| 239 | + $logger = $this->get('logger'); | |
| 240 | + $status = $request->getContent(); | |
| 241 | + $em = $this->getDoctrine()->getManager(); | |
| 237 | 242 | |
| 243 | + $dados = json_decode($status, true); | |
| 244 | + | |
| 245 | + $response = new JsonResponse(); | |
| 246 | + $response->setStatusCode('200'); | |
| 247 | + return $response; | |
| 238 | 248 | } |
| 239 | 249 | |
| 240 | 250 | /** |
| 241 | 251 | * Função para validar a sessão |
| 242 | 252 | */ |
| 243 | 253 | public function checkSession(Session $session) { |
| 254 | + $logger = $this->get('logger'); | |
| 244 | 255 | $session->getMetadataBag()->getCreated(); |
| 245 | 256 | $session->getMetadataBag()->getLastUsed(); |
| 246 | 257 | |
| 247 | 258 | if(time() - $session->getMetadataBag()->getLastUsed() > $this->maxIdleTime) { |
| 248 | 259 | $session->invalidate(); |
| 249 | - throw new SessionExpired(); // direciona para a página de sessão expirada | |
| 260 | + $logger->error("Sessão inválida:\n".$session->getId()); | |
| 261 | + //throw new SessionExpired(); // direciona para a página de sessão expirada | |
| 262 | + | |
| 250 | 263 | return false; |
| 251 | 264 | } |
| 252 | 265 | else{ | ... | ... |
src/Cacic/WSBundle/Resources/config/routing.yml
| ... | ... | @@ -50,7 +50,7 @@ cacic_neo_home: |
| 50 | 50 | schemes: [https] |
| 51 | 51 | |
| 52 | 52 | cacic_neo_home_login: |
| 53 | - pattern: /neo/login | |
| 53 | + pattern: /neo/getLogin | |
| 54 | 54 | defaults: { _controller: CacicWSBundle:Neo:login } |
| 55 | 55 | #schemes: [https] |
| 56 | 56 | |
| ... | ... | @@ -64,4 +64,8 @@ cacic_neo_home_gettest: |
| 64 | 64 | defaults: { _controller: CacicWSBundle:Neo:getTest } |
| 65 | 65 | #schemes: [https] |
| 66 | 66 | |
| 67 | +cacic_neo_home_config: | |
| 68 | + pattern: /neo/config | |
| 69 | + defaults: { _controller: CacicWSBundle:Neo:config } | |
| 70 | + #schemes: [https] | |
| 67 | 71 | ... | ... |
src/Cacic/WSBundle/Tests/Controller/NeoControllerTest.php
| ... | ... | @@ -43,7 +43,6 @@ class NeoControllerTest extends WebTestCase |
| 43 | 43 | '{}' |
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | - | |
| 47 | 46 | $logger = $this->container->get('logger'); |
| 48 | 47 | //$logger->debug("11111111111111111111111111111111111111 ".print_r($client->getRequest()->getUriForPath('/'), true)); |
| 49 | 48 | |
| ... | ... | @@ -53,13 +52,13 @@ class NeoControllerTest extends WebTestCase |
| 53 | 52 | /** |
| 54 | 53 | * test login |
| 55 | 54 | */ |
| 56 | - public function testLogin() | |
| 55 | + public function testGetLogin() | |
| 57 | 56 | { |
| 58 | 57 | |
| 59 | 58 | $logger = $this->container->get('logger'); |
| 60 | 59 | $this->client->request( |
| 61 | 60 | 'POST', |
| 62 | - '/ws/neo/login', | |
| 61 | + '/ws/neo/getLogin', | |
| 63 | 62 | array(), |
| 64 | 63 | array(), |
| 65 | 64 | array( |
| ... | ... | @@ -96,7 +95,7 @@ class NeoControllerTest extends WebTestCase |
| 96 | 95 | $logger = $this->container->get('logger'); |
| 97 | 96 | $this->client->request( |
| 98 | 97 | 'POST', |
| 99 | - '/ws/neo/login', | |
| 98 | + '/ws/neo/getLogin', | |
| 100 | 99 | array(), |
| 101 | 100 | array(), |
| 102 | 101 | array( |
| ... | ... | @@ -183,12 +182,63 @@ class NeoControllerTest extends WebTestCase |
| 183 | 182 | |
| 184 | 183 | $response = $this->client->getResponse(); |
| 185 | 184 | $status = $response->getStatusCode(); |
| 186 | - $logger->debug("Response status AAAAAAAAAAAAAAAAAAAAAAAAAAAA: $status"); | |
| 185 | + $logger->debug("Response status: $status"); | |
| 187 | 186 | |
| 188 | 187 | $this->assertEquals($status, 200); |
| 189 | 188 | |
| 190 | 189 | } |
| 191 | 190 | |
| 191 | + /** | |
| 192 | + * Testconfig | |
| 193 | + */ | |
| 194 | + public function testConfig() { | |
| 195 | + $logger = $this->container->get('logger'); | |
| 196 | + $this->client->request( | |
| 197 | + 'POST', | |
| 198 | + '/ws/neo/config', | |
| 199 | + array(), | |
| 200 | + array(), | |
| 201 | + array( | |
| 202 | + 'CONTENT_TYPE' => 'application/json', | |
| 203 | + //'HTTPS' => true | |
| 204 | + ), | |
| 205 | + '{ | |
| 206 | + "computador": { | |
| 207 | + "networkDevices": [ | |
| 208 | + { | |
| 209 | + "ipv4": "10.1.0.56", | |
| 210 | + "ipv6": "fe80::295b:a8db:d433:ebe%4", | |
| 211 | + "mac": "9C:D2:1E:EA:E0:89", | |
| 212 | + "netmask_ipv4": "255.255.255.0", | |
| 213 | + "netmask_ipv6": "ffff:ffff:ffff:ffff::", | |
| 214 | + "nome": "Wi-Fi" | |
| 215 | + }, | |
| 216 | + { | |
| 217 | + "ipv4": "192.168.56.1", | |
| 218 | + "ipv6": "fe80::19f2:4739:8a9e:45e4%16", | |
| 219 | + "mac": "08:00:27:00:14:2B", | |
| 220 | + "netmask_ipv4": "255.255.255.0", | |
| 221 | + "netmask_ipv6": "ffff:ffff:ffff:ffff::", | |
| 222 | + "nome": "VirtualBox Host-Only Network" | |
| 223 | + } | |
| 224 | + ], | |
| 225 | + "operatingSystem": { | |
| 226 | + "idOs": 176, | |
| 227 | + "nomeOs": "Windows_NT" | |
| 228 | + }, | |
| 229 | + "usuario": "Eric Menezes" | |
| 230 | + } | |
| 231 | + }' | |
| 232 | + ); | |
| 233 | + $logger->debug("Dados JSON do computador enviados \n".$this->client->getRequest()->getcontent()); | |
| 234 | + | |
| 235 | + $response = $this->client->getResponse(); | |
| 236 | + $status = $response->getStatusCode(); | |
| 237 | + $logger->debug("Response status: $status"); | |
| 238 | + | |
| 239 | + $this->assertEquals($status, 200); | |
| 240 | + | |
| 241 | + } | |
| 192 | 242 | |
| 193 | 243 | /** |
| 194 | 244 | * Método que apaga todos os dados criados no teste | ... | ... |