pi songsiritat avatar pi songsiritat committed 52af284

REFAPP-321: CTK tests for testing 3LO flag in OAuth consumer

Comments (0)

Files changed (2)

platform-ctk-plugin/src/main/java/com/atlassian/refapp/ctk/oauth/ServiceProviderConsumerStoreTest.java

         assertFalse(savedConsumer2.getTwoLOImpersonationAllowed());
     }
 
+    @Test
+    public void testIfConsumerDoesNotHave3LOFlagDefinedThenItIsConsideredOn() throws Exception
+    {
+        PublicKey publicKey = RSAKeys.fromPemEncodingToPublicKey(CONSUMER_PUBLIC_KEY);
+
+        final Consumer consumer = Consumer.key(CONSUMER_KEY)
+                .name("Test Consumer Name")
+                .publicKey(publicKey)
+                .description("Consumer Description")
+                .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"))
+                .build();
+        consumerStore.put(consumer);
+
+        final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY);
+        assertTrue(savedConsumer.getThreeLOAllowed());
+    }
+
+    @Test
+    public void testServiceProviderConsumerStoreCanStoreOAuth3LOConfiguration() throws Exception
+    {
+        PublicKey publicKey = RSAKeys.fromPemEncodingToPublicKey(CONSUMER_PUBLIC_KEY);
+
+        final Consumer consumer = Consumer.key(CONSUMER_KEY)
+                .name("Test Consumer Name")
+                .publicKey(publicKey)
+                .description("Consumer Description")
+                .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"))
+                .threeLOAllowed(false)
+                .build();
+        consumerStore.put(consumer);
+
+        final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY);
+        assertFalse(savedConsumer.getThreeLOAllowed());
+    }
+
+    @Test
+    public void testServiceProviderConsumerStoreCanHandle3LOConfigurationChanges() throws Exception
+    {
+        PublicKey publicKey = RSAKeys.fromPemEncodingToPublicKey(CONSUMER_PUBLIC_KEY);
+
+        final Consumer consumer = Consumer.key(CONSUMER_KEY)
+                .name("Test Consumer Name")
+                .publicKey(publicKey)
+                .description("Consumer Description")
+                .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"))
+                .threeLOAllowed(false)
+                .build();
+        consumerStore.put(consumer);
+
+        final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY);
+        assertFalse(savedConsumer.getThreeLOAllowed());
+
+        final Consumer consumer2 = Consumer.key(CONSUMER_KEY)
+                .name("Test Consumer Name")
+                .publicKey(publicKey)
+                .description("Consumer Description")
+                .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"))
+                .threeLOAllowed(true)
+                .build();
+        consumerStore.put(consumer2);
+
+        final Consumer savedConsumer2 = consumerStore.get(CONSUMER_KEY);
+        assertTrue(savedConsumer2.getThreeLOAllowed());
+    }
+
+    @Test
+    public void testServiceProviderConsumerStoreCanStoreConsumerWith2LOEnabledIndependently() throws Exception
+    {
+        PublicKey publicKey = RSAKeys.fromPemEncodingToPublicKey(CONSUMER_PUBLIC_KEY);
+
+        final Consumer consumer = Consumer.key(CONSUMER_KEY)
+                .name("Test Consumer Name")
+                .publicKey(publicKey)
+                .description("Consumer Description")
+                .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"))
+                .threeLOAllowed(false)
+                .twoLOAllowed(true)
+                .build();
+        consumerStore.put(consumer);
+
+        final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY);
+        assertFalse(savedConsumer.getThreeLOAllowed());
+        assertTrue(savedConsumer.getTwoLOAllowed());
+        assertFalse(savedConsumer.getTwoLOImpersonationAllowed());
+    }
+
+    @Test
+    public void testServiceProviderConsumerStoreCanStoreConsumerWith2LOWithImpersonationEnabledIndependently() throws Exception
+    {
+        PublicKey publicKey = RSAKeys.fromPemEncodingToPublicKey(CONSUMER_PUBLIC_KEY);
+
+        final Consumer consumer = Consumer.key(CONSUMER_KEY)
+                .name("Test Consumer Name")
+                .publicKey(publicKey)
+                .description("Consumer Description")
+                .callback(URI.create(appProp.getBaseUrl() + "/consumer/oauthcallback1"))
+                .threeLOAllowed(false)
+                .twoLOImpersonationAllowed(true)
+                .build();
+        consumerStore.put(consumer);
+
+        final Consumer savedConsumer = consumerStore.get(CONSUMER_KEY);
+        assertFalse(savedConsumer.getThreeLOAllowed());
+        assertFalse(savedConsumer.getTwoLOAllowed());
+        assertTrue(savedConsumer.getTwoLOImpersonationAllowed());
+    }
+
     @After
     public void tearDown()
     {
         <apl.version>3.10.4</apl.version>
 
         <oauth.name>OAuth</oauth.name>
-        <oauth.version>1.7.0</oauth.version>
+        <oauth.version>1.8.0-pi1</oauth.version>
 
         <rest.name>REST</rest.name>
         <rest.version>2.7.2</rest.version>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.