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

e2e test for elasticsearch token propagation #1705

Merged

Conversation

rubenvp8510
Copy link
Contributor

@rubenvp8510 rubenvp8510 commented Aug 1, 2019

Signed-off-by: Ruben Vargas ruben.vp8510@gmail.com

Which problem is this PR solving?

  • e2e tests for token propagation to ES

Short description of the changes

  • This is an integration test that make sure that the token reached ES storage.

@codecov
Copy link

codecov bot commented Aug 1, 2019

Codecov Report

Merging #1705 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1705      +/-   ##
==========================================
- Coverage   98.36%   98.32%   -0.05%     
==========================================
  Files         193      193              
  Lines        9358     9358              
==========================================
- Hits         9205     9201       -4     
- Misses        119      122       +3     
- Partials       34       35       +1
Impacted Files Coverage Δ
cmd/query/app/static_handler.go 83.33% <0%> (-3.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5f9953...628d228. Read the comment docs.

Copy link
Contributor

@objectiser objectiser left a comment

Choose a reason for hiding this comment

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

LGTM - just some minor

.travis.yml Outdated
@@ -75,6 +78,7 @@ script:
- if [ "$CASSANDRA_INTEGRATION_TEST" == true ]; then bash ./scripts/travis/cassandra-integration-test.sh ; else echo 'skipping cassandra integration test'; fi
- if [ "$HOTROD" == true ]; then bash ./scripts/travis/hotrod-integration-test.sh ; else echo 'skipping hotrod example'; fi
- if [ "$PROTO_GEN_TEST" == true ]; then make proto PROTOC=$HOME/protoc/bin/protoc && git diff --name-status --exit-code ; else echo 'skipping protoc validation'; fi
- if [ "TOKEN_INTEGRATION_TEST" == true ]; then bash ./scripts/travis/token-integration-test.sh ; else echo 'skipping protoc validation'; fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Message should be "skipping token propagation test".

.travis.yml Outdated
@@ -36,6 +36,9 @@ matrix:
- go: "1.12.1"
env:
- HOTROD=true
- go: "1.12.1"
env:
- TOKEN_INTEGRATION_TEST=true
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer it to be called TOKEN_PROPAGATION_TEST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll integrate into ES tests as @pavolloffay suggested.

const bearerToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsIm5hbWUiOiJKb2huIERvZSIsImlhdCI"
const bearerHeader = "Bearer " + bearerToken


Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Remove two lines.

}
stop := &sync.WaitGroup{}

go MockingESEToken(t, stop)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be a goroutine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I need to have this running in background mocking the ES, if I don't do this in a goroutine the function will run indefinitely listen on 9200 port, and the next section of the test won't be executed.

@pavolloffay
Copy link
Member

To keep the number of jobs low, could we add this test to ES_INTEGRATION_TEST test. There are already other tests related to ES.

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build token_propagation
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a space before so it's better visible

@rubenvp8510 rubenvp8510 force-pushed the token-propagation-e2e-simple branch 10 times, most recently from 9c86e36 to 5ee958c Compare August 3, 2019 02:39
.travis.yml Outdated
@@ -63,6 +63,9 @@ install:
curl -L https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip -o /tmp/protoc.zip
unzip /tmp/protoc.zip -d "$HOME"/protoc
fi
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 8.16.0
- npm install
- curl -o- -L https://yarnpkg.com/install.sh | bash
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this unconditionally in all matrix runs? It's only needed for steps where the UI is built, and I think it's already being installed there

Makefile Outdated
@@ -103,6 +103,11 @@ index-cleaner-integration-test: docker-images-elastic
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -tags index_cleaner $(STORAGE_PKGS) | $(COLORIZE)"

.PHONY: token-propagation-integration-test
query-integration-test:
Copy link
Member

Choose a reason for hiding this comment

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

target names don't match

@@ -9,3 +9,14 @@ STORAGE=elasticsearch make storage-integration-test
make index-cleaner-integration-test

docker kill $CID

make build-ui
Copy link
Member

Choose a reason for hiding this comment

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

why does this need the UI? It should only need query service API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I received errors when I tried to compile the query service alone,.

Copy link
Member

Choose a reason for hiding this comment

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

we build query service for crossdock using a mock UI, check that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll check it, Thanks!

req.Header.Add(testCase.headerName, testCase.headerValue)
assert.NoError(t, err)
client := &http.Client{}
_, err = client.Do(req)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a valid test, the query service can simply ignore the tokens, the test is not validating anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? If query service ignore the token, the handler in the elasticsearch mocker won't received it and the test will fail.

Copy link
Member

Choose a reason for hiding this comment

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

but the ESMock doesn't return any sensible results, the query service will fail anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha sure, I'm not validating if the query service returns results or not, I only validate that the token is being propagated to the ES storage. I of course can implement a better mock of ES if you think we need to validate the query reply

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to the nature of the e2e tests I decided to follow your recommendation, now I returned an empty result if with an http 200 if the token was received with mocked ES, and 403 (forbidden http) otherwise.

So the test validates that the query service propagated the token correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the test better now?

@rubenvp8510 rubenvp8510 force-pushed the token-propagation-e2e-simple branch 8 times, most recently from b744067 to aab79fe Compare August 4, 2019 02:26
@rubenvp8510 rubenvp8510 closed this Aug 5, 2019
@rubenvp8510 rubenvp8510 reopened this Aug 5, 2019
@rubenvp8510 rubenvp8510 force-pushed the token-propagation-e2e-simple branch 4 times, most recently from 0265690 to 8511d74 Compare August 5, 2019 16:14
@rubenvp8510 rubenvp8510 closed this Aug 5, 2019
@rubenvp8510 rubenvp8510 reopened this Aug 5, 2019
@rubenvp8510 rubenvp8510 force-pushed the token-propagation-e2e-simple branch 7 times, most recently from 3ebf761 to a39956c Compare August 8, 2019 11:33
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
}

func CreateElasticSearchMock(srv *http.Server, t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

private? should not be capitalized

}
}

func Test_bearTokenPropagation(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

TestBearerTokenPropagation

// Ask for services query, this should return 200
req, err := http.NewRequest("GET", queryUrl, nil)
req.Header.Add(testCase.headerName, testCase.headerValue)
assert.NoError(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

move one line above. Should use require instead of assert since you can't continue the test on error

assert.NoError(t, err)
client := &http.Client{}
resp, err := client.Do(req)
// Should not have errors.
Copy link
Member

Choose a reason for hiding this comment

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

redundant comment

client := &http.Client{}
resp, err := client.Do(req)
// Should not have errors.
assert.Nil(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

assert.NoError

}
}

srv.Shutdown(context.Background())
Copy link
Member

Choose a reason for hiding this comment

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

move to next line after creating a server and invoke via defer, to keep housekeeping logic together

@rubenvp8510 rubenvp8510 force-pushed the token-propagation-e2e-simple branch 3 times, most recently from de4e4fc to ef3302c Compare August 10, 2019 16:18
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
@rubenvp8510
Copy link
Contributor Author

Ok, I addressed all comments, @yurishkuro thanks for the review!

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

Thanks!

@yurishkuro yurishkuro merged commit 0341a42 into jaegertracing:master Aug 10, 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.

4 participants