Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed middleware and dao test of auth plugin #28

Merged
merged 6 commits into from
Sep 11, 2019
Merged

Conversation

abhinavraj23
Copy link

What does this do / why do we need it?

The middleware test was giving an error as the getRolePermission method was not implemented. I
have implemented the method and now the tests are working.

What should your reviewer look out for in this PR?

Check if the implemented method is correct and if I have made a valid change or not

Which issue(s) does this PR fix?

Partially fixes one part of #17

@abhinavraj23 abhinavraj23 self-assigned this Aug 25, 2019
@jeet-parekh
Copy link

jeet-parekh commented Sep 1, 2019

I tried this test, and it failed for me.

--- FAIL: TestBasicAuthWithJWToken (0.29s)
    /home/jeet/code-reviews/arc/plugins/auth/middleware_test.go:244: FAIL:	getCredential(*context.valueCtx,string)
        		at: [middleware_test.go:238]
    /home/jeet/code-reviews/arc/plugins/auth/middleware_test.go:244: FAIL: 0 out of 1 expectation(s) were met.
        	The code you are testing needs to make 1 more call(s).
        	at: [middleware_test.go:244]
    /home/jeet/code-reviews/arc/plugins/auth/middleware_test.go:245: 
        	Error Trace:	middleware_test.go:245
        	Error:      	Not equal: 
        	            	expected: 200
        	            	actual  : 401
        	Test:       	TestBasicAuthWithJWToken
--- FAIL: TestBasicAuthWithJWTokenWithoutUser (0.42s)
    /home/jeet/code-reviews/arc/plugins/auth/middleware_test.go:282: FAIL:	getCredential(*context.valueCtx,string)
        		at: [middleware_test.go:276]
    /home/jeet/code-reviews/arc/plugins/auth/middleware_test.go:282: FAIL: 0 out of 1 expectation(s) were met.
        	The code you are testing needs to make 1 more call(s).
        	at: [middleware_test.go:282]
FAIL
FAIL	github.com/appbaseio/arc/plugins/auth	1.178s
Error: Tests failed.

This is what I did...

I started an ESv7 server inside docker

sudo docker run -d --name elasticsearch --hostname elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "transport.host=127.0.0.1" elasticsearch:7.0.0

Then I built arc

make && make plugins

Then I ran arc

./build/arc --log=stdout --env=config/manual.env

2019/09/01 09:11:41 main.go:86: You're running Arc with billing module disabled.
2019/09/01 09:11:41 registry.go:71: [registry]: Initializing plugin: [auth]
2019/09/01 09:11:41 registry.go:71: [registry]: Initializing plugin: [logs]
2019/09/01 09:11:41 dao.go:61: [logs]: successfully created index name ".logs"
2019/09/01 09:11:41 registry.go:71: [registry]: Initializing plugin: [permissions]
2019/09/01 09:11:41 permissions.go:42: [permissions]: initializing plugin
2019/09/01 09:11:41 dao.go:63: [permissions] successfully created index named '.permissions'
2019/09/01 09:11:41 registry.go:71: [registry]: Initializing plugin: [reindexer]
2019/09/01 09:11:41 registry.go:71: [registry]: Initializing plugin: [users]
2019/09/01 09:11:41 dao.go:80: [users] successfully created index named '.users'
2019/09/01 09:11:42 registry.go:80: [registry]: Initializing plugin: [elasticsearch]
2019/09/01 09:11:42 routes.go:175: [elasticsearch]: unable to categorize spec "info": info does not belong to ACL values\n
2019/09/01 09:11:42 routes.go:175: [elasticsearch]: unable to categorize spec "ping": ping does not belong to ACL values\n
2019/09/01 09:11:42 main.go:122: [cmd]: listening on :8000

And then, running the tests gave me the above error.

If it works for you, let me know what I need to do to fix this.

Copy link

@jeet-parekh jeet-parekh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment unrelated to these changes.

@abhinavraj23
Copy link
Author

abhinavraj23 commented Sep 1, 2019

@jeet-parekh let me check, well initially the whole file was giving an error and none of the tests were working due to one function which not which wasn't implemented I just implemented that method, now at-least 10 out of 16 tests are passing. I am working on making other tests work

=== RUN   TestGetPermission
--- PASS: TestGetPermission (0.00s)
=== RUN   TestGetPermission/getPermissionTest
    --- PASS: TestGetPermission/getPermissionTest (0.00s)
=== RUN   TestGetUser
--- PASS: TestGetUser (0.00s)
=== RUN   TestGetUser/getPermissionTest
    --- PASS: TestGetUser/getPermissionTest (0.00s)
=== RUN   TestPutUser
--- PASS: TestPutUser (0.00s)
=== RUN   TestPutUser/getPermissionTest
    --- PASS: TestPutUser/getPermissionTest (0.00s)
=== RUN   TestPutPermission
--- FAIL: TestPutPermission (0.00s)
=== RUN   TestPutPermission/getPermissionTest
    --- FAIL: TestPutPermission/getPermissionTest (0.00s)
        dao_test.go:63: No requests matched setup. Got method PUT, Path /perm/_doc/user1, body {"username":"user1","password":"pass1","owner":"owner1","creator":"creator1","role":"","categories":["docs"],"acls":["update"],"ops":["write"],"indices":["test"],"sources":["source"],"referers":["referers"],"created_at":"mon","ttl":1,"limits":{"ip_limit":7200,"docs_limit":30,"search_limit":30,"indices_limit":30,"cat_limit":30,"clusters_limit":30,"misc_limit":30},"description":"permissions payload"}
             PUT:/perm/_doc/user1
        dao_test.go:244: Cat aliases should have failed with error:  got: Put http://127.0.0.1:51386/perm/_doc/user1: EOF instead
=== RUN   TestGetCredential
--- FAIL: TestGetCredential (0.00s)
=== RUN   TestGetCredential/getPermissionTest
    --- FAIL: TestGetCredential/getPermissionTest (0.00s)
        dao_test.go:301: Cat aliases should have failed with error:  got: json: cannot unmarshal number into Go struct field SearchHits.total of type elastic.TotalHits instead
=== RUN   TestBasicAuthWithUserPasswordBasic
--- PASS: TestBasicAuthWithUserPasswordBasic (0.13s)
    middleware_test.go:95: PASS:	getCredential(*context.valueCtx,string)
=== RUN   TestBasicAuthWithUserPasswordWithoutUser
--- PASS: TestBasicAuthWithUserPasswordWithoutUser (0.00s)
    middleware_test.go:123: PASS:	getCredential(*context.valueCtx,string)
=== RUN   TestBasicAuthWithUserWrongPassword
--- PASS: TestBasicAuthWithUserWrongPassword (0.13s)
    middleware_test.go:155: PASS:	getCredential(*context.valueCtx,string)
=== RUN   TestBasicAuthTwoRequests
--- PASS: TestBasicAuthTwoRequests (0.20s)
    middleware_test.go:203: PASS:	getCredential(*context.valueCtx,string)
=== RUN   TestBasicAuthWithJWToken
--- FAIL: TestBasicAuthWithJWToken (0.27s)
    middleware_test.go:244: FAIL:	getCredential(*context.valueCtx,string)
        		at: [middleware_test.go:238]
    middleware_test.go:244: FAIL: 0 out of 1 expectation(s) were met.
        	The code you are testing needs to make 1 more call(s).
        	at: [middleware_test.go:244]
    middleware_test.go:245: 
        	Error Trace:	middleware_test.go:245
        	Error:      	Not equal: 
        	            	expected: 200
        	            	actual  : 401
        	Test:       	TestBasicAuthWithJWToken


Expected :200
Actual   :401
<Click to see difference>


=== RUN   TestBasicAuthWithJWTokenWithoutUser
--- FAIL: TestBasicAuthWithJWTokenWithoutUser (0.06s)
    middleware_test.go:282: FAIL:	getCredential(*context.valueCtx,string)
        		at: [middleware_test.go:276]
    middleware_test.go:282: FAIL: 0 out of 1 expectation(s) were met.
        	The code you are testing needs to make 1 more call(s).
        	at: [middleware_test.go:282]
FAIL

Copy link

@jeet-parekh jeet-parekh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any changes after the last review. Did you change anything?

TestBasicAuthWithJWToken and TestBasicAuthWithJWTokenWithoutUser still fail for me. Those are the only two which failed for me earlier as well. All the other tests worked.

@abhinavraj23 abhinavraj23 changed the title Fixed middleware test of plugins Fixed middleware and dao test of auth plugin Sep 10, 2019
@abhinavraj23
Copy link
Author

@jeet-parekh other than the jwtToken test all other authentication tests (dao and middleware)are fixed and are now correctly working and passing as well. I am confused with how to solve jwtTokenAuthentication and I am unable to fix, I am still trying to fix it.

@jeet-parekh
Copy link

@abhinavraj23, I didn't know that the other tests were failing. Good thing that you fixed it!

I'm confused about the JWT tests as well. Do you understand the error?

The code you are testing needs to make 1 more call(s)

If no, but if you understand what the test is supposed to be doing... try to write a new test function entirely on your own (doesn't need to follow the "structure" of the previous tests). It would be easier that way.

@abhinavraj23
Copy link
Author

abhinavraj23 commented Sep 10, 2019

@jeet-parekh I have solved the issue and the jwt test are working fine!!, now all the 16 tests of authentication are working and are passing.

=== RUN TestGetPermission --- PASS: TestGetPermission (0.00s) === RUN TestGetPermission/getPermissionTest --- PASS: TestGetPermission/getPermissionTest (0.00s) === RUN TestGetUser --- PASS: TestGetUser (0.00s) === RUN TestGetUser/getPermissionTest --- PASS: TestGetUser/getPermissionTest (0.00s) === RUN TestPutUser --- PASS: TestPutUser (0.00s) === RUN TestPutUser/getPermissionTest --- PASS: TestPutUser/getPermissionTest (0.00s) === RUN TestPutPermission --- PASS: TestPutPermission (0.00s) === RUN TestPutPermission/getPermissionTest --- PASS: TestPutPermission/getPermissionTest (0.00s) === RUN TestGetCredential --- PASS: TestGetCredential (0.00s) === RUN TestGetCredential/getPermissionTest --- PASS: TestGetCredential/getPermissionTest (0.00s) === RUN TestBasicAuthWithUserPasswordBasic --- PASS: TestBasicAuthWithUserPasswordBasic (0.13s) middleware_test.go:95: PASS: getCredential(*context.valueCtx,string) === RUN TestBasicAuthWithUserPasswordWithoutUser --- PASS: TestBasicAuthWithUserPasswordWithoutUser (0.00s) middleware_test.go:123: PASS: getCredential(*context.valueCtx,string) === RUN TestBasicAuthWithUserWrongPassword --- PASS: TestBasicAuthWithUserWrongPassword (0.13s) middleware_test.go:155: PASS: getCredential(*context.valueCtx,string) === RUN TestBasicAuthTwoRequests --- PASS: TestBasicAuthTwoRequests (0.19s) middleware_test.go:203: PASS: getCredential(*context.valueCtx,string) === RUN TestBasicAuthWithJWToken --- PASS: TestBasicAuthWithJWToken (0.21s) middleware_test.go:244: PASS: getCredential(*context.valueCtx,string) === RUN TestBasicAuthWithJWTokenWithoutUser --- PASS: TestBasicAuthWithJWTokenWithoutUser (0.15s) middleware_test.go:282: PASS: getCredential(*context.valueCtx,string) PASS

Copy link

@jeet-parekh jeet-parekh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! The tests pass now. LGTM

@jeet-parekh jeet-parekh merged commit ec7dc49 into feat/es7 Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants