mushorg / tanner

He who flays the hide
GNU General Public License v3.0
222 stars 103 forks source link

MySQL DB Helper Tests #315

Closed rjt-gupta closed 5 years ago

rjt-gupta commented 5 years ago

Some pointers -

rjt-gupta commented 5 years ago

The tests are passing locally, I dont understand why it fails here.

rnehra01 commented 5 years ago

Look at the logs and try to understand the errors. I'll look at it tomorrow.

rnehra01 commented 5 years ago

You need to update the Travis file to use MySql service https://docs.travis-ci.com/user/database-setup/#mysql. Also, consider the password the and username.

rjt-gupta commented 5 years ago

You need to update the Travis file to use MySql service https://docs.travis-ci.com/user/database-setup/#mysql. Also, consider the password the and username.

Just when I wanted to learn more about travis. Awesome!

coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 955


Files with Coverage Reduction New Missed Lines %
tanner/emulators/php_code_injection.py 2 82.61%
tanner/emulators/rfi.py 6 87.34%
tanner/emulators/base.py 8 91.11%
<!-- Total: 16 -->
Totals Coverage Status
Change from base Build 939: 5.2%
Covered Lines: 1132
Relevant Lines: 1677

💛 - Coveralls
rjt-gupta commented 5 years ago

Done Finally :)

rnehra01 commented 5 years ago

What about other methods?

rjt-gupta commented 5 years ago

Yes about that insert_dummy_data will be added to test_mysqli which I will push in some time. But the copy_db method creates the database in /var/lib/mysql/* directory. So im not sure how to test this.

rnehra01 commented 5 years ago

What is the problem?

rjt-gupta commented 5 years ago

What is the problem?

Travis build fails to enter /var/lib/mysql and prompts for password. Im doing more research to come up with a fix.

rjt-gupta commented 5 years ago

So, I can't directly use copy_db method because of /var/lib/mysql permissions. Any other way to test?

rnehra01 commented 5 years ago

I don't think its related to any permissions. https://github.com/rjt-gupta/tanner/blob/19b7dfb7dc938586fb7aa50c390faed1cff75867/tanner/utils/mysql_db_helper.py#L73 this is the reason of prompt since password is empty so -p flag causes a prompt, had it been a non-empty password it would have worked fine

rjt-gupta commented 5 years ago

So, I guess removing the -p flag should fix the problem. Let me try.

rjt-gupta commented 5 years ago

Worked Great!

rjt-gupta commented 5 years ago

So, diff is giving some mysql version specific comment but locally tests are passing. I think they are of not much use here and I could grep and remove such type of output but should I do this?

Refs - https://dev.mysql.com/doc/refman/8.0/en/comments.html

rnehra01 commented 5 years ago

So, diff is giving some mysql version specific comment but locally tests are passing. I think they are of not much use here and I could grep and remove such type of output but should I do this?

Refs - https://dev.mysql.com/doc/refman/8.0/en/comments.html

I think you can use querymap method to check existense of tables.

rjt-gupta commented 5 years ago

So, diff is giving some mysql version specific comment but locally tests are passing. I think they are of not much use here and I could grep and remove such type of output but should I do this?

Refs - https://dev.mysql.com/doc/refman/8.0/en/comments.html

No, this is im refering for copy_db tests as there im using diff to get the difference in the DB dumps. Checking the tables in setup_db_from_config is working fine.

rnehra01 commented 5 years ago

Read this https://stackoverflow.com/questions/225772/compare-two-mysql-databases , they are discussing about flags like --opt, --compact to furthur reduce comments. I don't think grepping is good.

rjt-gupta commented 5 years ago

Read this https://stackoverflow.com/questions/225772/compare-two-mysql-databases , they are discussing about flags like --opt, --compact to furthur reduce comments. I don't think grepping is good.

Okay, will try out those but I don't get why the tests are passing locally?

rnehra01 commented 5 years ago

Maybe check if travis has different version

Ravinder Nehra

On Tue, Jun 4, 2019, 10:04 Rajat Gupta notifications@github.com wrote:

Read this https://stackoverflow.com/questions/225772/compare-two-mysql-databases , they are discussing about flags like --opt, --compact to furthur reduce comments. I don't think grepping is good.

Okay, will try out those but I don't get why the tests are passing locally?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mushorg/tanner/pull/315?email_source=notifications&email_token=AD64W2EGYZMCS5M57DOOZFDPYXWE3A5CNFSM4HNI32JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW3MLEI#issuecomment-498517393, or mute the thread https://github.com/notifications/unsubscribe-auth/AD64W2EYHI7SQGFH2OM6ISDPYXWE3ANCNFSM4HNI32JA .

rjt-gupta commented 5 years ago

Worked Great!

rnehra01 commented 5 years ago

Well that should not happen. Also you write code related to multiple calls earlier. Analyze carefully because if it's not then there is something wrong with it.

Ravinder Nehra

On Tue, Jun 4, 2019, 23:21 Rajat Gupta notifications@github.com wrote:

@rjt-gupta commented on this pull request.

In tanner/tests/test_mysql_db_helper.py https://github.com/mushorg/tanner/pull/315#discussion_r290419750:

  • self.handler.read_config = mock_read_config
  • self.handler.insert_dummy_data = AsyncMock()
  • async def test():
  • await self.handler.setup_db_from_config()
  • for table in config["tables"]:
  • await self.cursor.execute('USE test_db')
  • await self.cursor.execute('DESCRIBE {table_name}'.format(table_name=table["table_name"]))
  • result = await self.cursor.fetchall()
  • self.result.append(result)
  • self.loop.run_until_complete(test())
  • self.assertEqual(self.result, self.expected_result)
  • self.handler.insert_dummy_data.assert_called_with('CREDS', 'I,E,P', mock.ANY)

I have checked that but setupdbfromconfig call is only returning the last table used.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mushorg/tanner/pull/315?email_source=notifications&email_token=AD64W2G757KOOP2YQC2JU2TPY2TRXA5CNFSM4HNI32JKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB2R2DKI#discussion_r290419750, or mute the thread https://github.com/notifications/unsubscribe-auth/AD64W2DZZ7YU6VB67JQPC7LPY2TRXANCNFSM4HNI32JA .

rjt-gupta commented 5 years ago

Done.