jeffwils / grails-spring-security-saml

Grails Spring Security SAML2.0 Plugin for Grails 3
8 stars 24 forks source link

Unit tests Failing? #14

Closed slick666 closed 6 years ago

slick666 commented 6 years ago

Hey All,

I'm new to grails, gradle, so I apologize if this issue is off base. I ran into errors simply cloning and building the plugin

$ ./gradlew clean build

The first round or errors all came from the director below

https://github.com/jeffwils/grails-spring-security-saml/tree/master/src/test/groovy/test

All of these tests seem to be stubbed out tests that don't do anything. After removing that entire directory I got real errors from the rest of the errors but I'm thinking these are all part of a simple environment setting or something simple. I'm hoping someone here will have worked through this before.

$ ./gradlew clean build [buildinfo] Not using buildInfo properties file for this build. :clean :compileAstJava UP-TO-DATE :compileAstGroovy UP-TO-DATE :processAstResources UP-TO-DATE :astClasses UP-TO-DATE :compileJava warning: [options] bootstrap class path not set in conjunction with -source 1.7 1 warning :configScript :compileGroovy :copyAstClasses UP-TO-DATE :copyCommands UP-TO-DATE :copyTemplates UP-TO-DATE :processResources :classes :compileTestJava UP-TO-DATE :compileTestGroovy :processTestResources UP-TO-DATE :testClasses :compileIntegrationTestJava UP-TO-DATE :compileIntegrationTestGroovy startup failed: /Users/land8150/workspace/grails-spring-security-saml/src/integration-test/groovy/org/grails/plugin/springsecurity/saml/SpringSamlUserDetailsServiceIntegrationSpec.groovy: 6: unable to resolve class spock.lang.Specification @ line 6, column 1. import spock.lang.Specification ^

1 error

:compileIntegrationTestGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':compileIntegrationTestGroovy'. > Compilation failed; see the compiler error output for details.

* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 17.647 secs

Please let me know your thoughts on this issue I suspect it's something simple on my end.

Cheers Landon

irstevenson commented 6 years ago

Heya @slick666

This repo is missing a couple of key files to allow the wrapper to work out of the box (as I'm guessing you noticed seeing you got as far as you did). But from what I can figure it's meant to be a grails 3.1.9 project. So based on that I did the following to get it building after a fresh clone (on master branch):

  1. Created a skeleton grails 3.1.9 project in /tmp/grskel
  2. In this plugin's working dir (e.g. /tmp/grails-spring-security-saml) remove the gradle dir
  3. Copy the /tmp/grskel/gradle dir into /tmp/grails-spring-security-saml dir
  4. Copy the /tmp/grskel/gradle.properties into /tmp/grails-spring-security-saml dir

And then with java 1.8.0_152 I was able to successfully do:

  1. ./gradlew clean followed by
  2. ./gradlew build

However, with failed integration tests as I'd need to tweak it to talk to my IdP etc. But at least the tests run with no compilation errors.

P.S. And seeing you mention you're new to grails, an easy way to swap between versions (to create the skeleton project for example) is to use SDK man.

P.S.S. Ideally all these files would be in the project, and I see that the fork over at https://github.com/valentingoebel/grails-spring-security-saml/tree/mainlining is doing that (or along those lines).

irstevenson commented 6 years ago

Further to the above, yes those are a collection of stubbed tests auto generated by grails.

Once we've got the 3.3.x support (see #12) going I'm going to attempt to tidy up the tests.

valentingoebel commented 6 years ago

Take a look at http://docs.grails.org/latest/guide/testing.html#unitTesting

You can add this dependency in build.gradle as a temporary measure:

testCompile "org.grails:grails-test-mixins:3.3.0.RC1"

The tests are able to run but a large number of them are failing.

A long term solution is to convert the tests by following this guide:

https://testing.grails.org/latest/guide/index.html

Key changes:

  1. All tests should extend Specification
  2. @TestFor(X) is now implements ControllerUnitTest<X>
  3. @Mock(X) is now DomainUnitTest<X>
  4. DataTest + mockDomain can be used to test multiple domain classes
irstevenson commented 6 years ago

Turns out this issue even a bit more fun. The tests not only need to be updated to use the new framework, they also need to be converted from jUnit to Spock.

Anyway, with commit 56485a7 the unit tests now compile. Now working through conversion from jUnit.

valentingoebel commented 6 years ago

Did you migrate the integration test?

SpringSamlUserDetailsServiceIntegrationSpec fails to compile for me.

irstevenson commented 6 years ago

Heya @valentingoebel ,

Not yet, still going - slowed down due to Easter and work bits. But I think I should be able to hammer this down in the next day or so. Progress can be seen on the branch at:

https://github.com/jeffwils/grails-spring-security-saml/tree/issue_14_upgrade_tests

Almost got the unit tests down, just three test failures to fix then I'll jump on the integration tests. But yes integration tests still failing compilation at the moment.

irstevenson commented 6 years ago

Alright, this has been an insightful process. As a number of tests were failing in odd ways, and it was also interesting all the tests were still jUnit - even though Spock came in around about grails 2.2.

Turns out a lot of this is still the original code from: https://grails.org/plugin/spring-security-saml

Then tweaks have been made over time, and the tests have fallen behind. So where tests have failed, I've fixed them to match the current code - as considering people are using this plugin, we have the assume that's now the way it should work.

irstevenson commented 6 years ago

Please see PR #30 .

irstevenson commented 6 years ago

Tests are now all working again on master. Simply:

./gradlew clean check

And all should pass.

Closing ticket.