@@ -58,6 +58,7 @@ var cohortDefinitionControllerNeedsDb = controllers.NewCohortDefinitionControlle
58
58
59
59
// instance of the controller that talks to a mock implementation of the model:
60
60
var cohortDefinitionController = controllers .NewCohortDefinitionController (* new (dummyCohortDefinitionDataModel ), * new (dummyTeamProjectAuthz ))
61
+ var cohortDefinitionControllerWithFailingTeamProjectAuthz = controllers .NewCohortDefinitionController (* new (dummyCohortDefinitionDataModel ), * new (dummyFailingTeamProjectAuthz ))
61
62
62
63
type dummyCohortDataModel struct {}
63
64
@@ -482,7 +483,6 @@ func TestRetriveStatsBySourceIdAndTeamProject(t *testing.T) {
482
483
requestContext .Writer = new (tests.CustomResponseWriter )
483
484
cohortDefinitionController .RetriveStatsBySourceIdAndTeamProject (requestContext )
484
485
result := requestContext .Writer .(* tests.CustomResponseWriter )
485
- log .Printf ("result: %s" , result )
486
486
// expect result with all of the dummy data:
487
487
if ! strings .Contains (result .CustomResponseWriterOut , "name1_" + teamProject ) ||
488
488
! strings .Contains (result .CustomResponseWriterOut , "name2_" + teamProject ) ||
@@ -510,7 +510,6 @@ func TestRetriveById(t *testing.T) {
510
510
requestContext .Writer = new (tests.CustomResponseWriter )
511
511
cohortDefinitionController .RetriveById (requestContext )
512
512
result := requestContext .Writer .(* tests.CustomResponseWriter )
513
- log .Printf ("result: %s" , result )
514
513
// expect result with dummy data:
515
514
if ! strings .Contains (result .CustomResponseWriterOut , "test 1" ) {
516
515
t .Errorf ("Expected data in result" )
@@ -530,6 +529,26 @@ func TestRetriveByIdModelError(t *testing.T) {
530
529
}
531
530
}
532
531
532
+ func TestRetriveByIdAuthorizationError (t * testing.T ) {
533
+ setUp (t )
534
+ requestContext := new (gin.Context )
535
+ requestContext .Params = append (requestContext .Params , gin.Param {Key : "id" , Value : "1" })
536
+ requestContext .Writer = new (tests.CustomResponseWriter )
537
+ cohortDefinitionControllerWithFailingTeamProjectAuthz .RetriveById (requestContext )
538
+ result := requestContext .Writer .(* tests.CustomResponseWriter )
539
+ if ! requestContext .IsAborted () {
540
+ t .Errorf ("Expected aborted request" )
541
+ }
542
+ if result .Status () != http .StatusForbidden {
543
+ t .Errorf ("Expected StatusForbidden, got %d" , result .Status ())
544
+ }
545
+ // expect result with dummy data:
546
+ if ! strings .Contains (result .CustomResponseWriterOut , "access denied" ) {
547
+ t .Errorf ("Expected 'access denied' in response" )
548
+ }
549
+
550
+ }
551
+
533
552
func TestRetrieveBreakdownStatsBySourceIdAndCohortId (t * testing.T ) {
534
553
setUp (t )
535
554
requestContext := new (gin.Context )
@@ -540,7 +559,6 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortId(t *testing.T) {
540
559
requestContext .Writer = new (tests.CustomResponseWriter )
541
560
conceptController .RetrieveBreakdownStatsBySourceIdAndCohortId (requestContext )
542
561
result := requestContext .Writer .(* tests.CustomResponseWriter )
543
- log .Printf ("result: %s" , result )
544
562
// expect result with dummy data:
545
563
if ! strings .Contains (result .CustomResponseWriterOut , "persons_in_cohort_with_value" ) {
546
564
t .Errorf ("Expected data in result" )
@@ -571,7 +589,6 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndVariables(t *testing.T) {
571
589
requestContext .Writer = new (tests.CustomResponseWriter )
572
590
conceptController .RetrieveBreakdownStatsBySourceIdAndCohortIdAndVariables (requestContext )
573
591
result := requestContext .Writer .(* tests.CustomResponseWriter )
574
- log .Printf ("result: %s" , result )
575
592
// expect result with dummy data:
576
593
if ! strings .Contains (result .CustomResponseWriterOut , "persons_in_cohort_with_value" ) {
577
594
t .Errorf ("Expected data in result" )
@@ -616,7 +633,6 @@ func TestRetrieveInfoBySourceIdAndConceptIds(t *testing.T) {
616
633
requestContext .Writer = new (tests.CustomResponseWriter )
617
634
conceptController .RetrieveInfoBySourceIdAndConceptIds (requestContext )
618
635
result := requestContext .Writer .(* tests.CustomResponseWriter )
619
- log .Printf ("result: %s" , result )
620
636
// expect result with dummy data:
621
637
if ! strings .Contains (result .CustomResponseWriterOut , "Concept A" ) ||
622
638
! strings .Contains (result .CustomResponseWriterOut , "Concept B" ) {
@@ -633,7 +649,6 @@ func TestRetrieveInfoBySourceIdAndConceptTypes(t *testing.T) {
633
649
requestContext .Writer = new (tests.CustomResponseWriter )
634
650
conceptController .RetrieveInfoBySourceIdAndConceptTypes (requestContext )
635
651
result := requestContext .Writer .(* tests.CustomResponseWriter )
636
- log .Printf ("result: %s" , result )
637
652
// expect result with dummy data:
638
653
if ! strings .Contains (result .CustomResponseWriterOut , "Concept A" ) ||
639
654
! strings .Contains (result .CustomResponseWriterOut , "Concept B" ) {
@@ -652,7 +667,6 @@ func TestRetrieveInfoBySourceIdAndConceptTypesModelError(t *testing.T) {
652
667
dummyModelReturnError = true
653
668
conceptController .RetrieveInfoBySourceIdAndConceptTypes (requestContext )
654
669
result := requestContext .Writer .(* tests.CustomResponseWriter )
655
- log .Printf ("result: %s" , result )
656
670
if ! requestContext .IsAborted () {
657
671
t .Errorf ("Expected aborted request" )
658
672
}
@@ -670,7 +684,6 @@ func TestRetrieveInfoBySourceIdAndConceptTypesArgsError(t *testing.T) {
670
684
dummyModelReturnError = true
671
685
conceptController .RetrieveInfoBySourceIdAndConceptTypes (requestContext )
672
686
result := requestContext .Writer .(* tests.CustomResponseWriter )
673
- log .Printf ("result: %s" , result )
674
687
if ! requestContext .IsAborted () {
675
688
t .Errorf ("Expected aborted request" )
676
689
}
@@ -688,7 +701,6 @@ func TestRetrieveInfoBySourceIdAndConceptTypesMissingBody(t *testing.T) {
688
701
dummyModelReturnError = true
689
702
conceptController .RetrieveInfoBySourceIdAndConceptTypes (requestContext )
690
703
result := requestContext .Writer .(* tests.CustomResponseWriter )
691
- log .Printf ("result: %s" , result )
692
704
if ! requestContext .IsAborted () {
693
705
t .Errorf ("Expected aborted request" )
694
706
}
@@ -990,7 +1002,6 @@ func TestRetrieveAttritionTable(t *testing.T) {
990
1002
requestContext .Writer = new (tests.CustomResponseWriter )
991
1003
conceptController .RetrieveAttritionTable (requestContext )
992
1004
result := requestContext .Writer .(* tests.CustomResponseWriter )
993
- log .Printf ("result: %s" , result .CustomResponseWriterOut )
994
1005
// check result vs expect result:
995
1006
csvLines := strings .Split (strings .TrimRight (result .CustomResponseWriterOut , "\n " ), "\n " )
996
1007
expectedLines := []string {
0 commit comments