@Test public void createExistingTag() throws Exception { grantTagPermissions(); TagInput input = new TagInput(); input.ref = "test"; TagInfo result = tag(input.ref).create(input).get(); assertThat(result.ref).isEqualTo(R_TAGS + "test"); input.ref = "refs/tags/test"; exception.expect(ResourceConflictException.class); exception.expectMessage("tag \"" + R_TAGS + "test\" already exists"); tag(input.ref).create(input); }
@Test public void createTagNotAllowed() throws Exception { TagInput input = new TagInput(); input.ref = "test"; exception.expect(AuthException.class); exception.expectMessage("Cannot create tag \"" + R_TAGS + "test\""); tag(input.ref).create(input); }
@Test public void mismatchedInput() throws Exception { TagInput input = new TagInput(); input.ref = "test"; exception.expect(BadRequestException.class); exception.expectMessage("ref must match URL"); tag("TEST").create(input); }
@Test public void createSignedTagNotSupported() throws Exception { TagInput input = new TagInput(); input.ref = "test"; input.message = SIGNED_ANNOTATION; exception.expect(MethodNotAllowedException.class); exception.expectMessage("Cannot create signed tag \"" + R_TAGS + "test\""); tag(input.ref).create(input); }
@Test public void createAnnotatedTagNotAllowed() throws Exception { block(Permission.PUSH_TAG, REGISTERED_USERS, R_TAGS + "*"); TagInput input = new TagInput(); input.ref = "test"; input.message = "annotation"; exception.expect(AuthException.class); exception.expectMessage("Cannot create annotated tag \"" + R_TAGS + "test\""); tag(input.ref).create(input); }
@Test public void invalidTagNameOnlySlashes() throws Exception { grantTagPermissions(); TagInput input = new TagInput(); input.ref = "//"; exception.expect(BadRequestException.class); exception.expectMessage("invalid tag name \"refs/tags/\""); tag(input.ref).create(input); }
@Test public void invalidTagName() throws Exception { grantTagPermissions(); TagInput input = new TagInput(); input.ref = "refs/heads/test"; exception.expect(BadRequestException.class); exception.expectMessage("invalid tag name \"" + input.ref + "\""); tag(input.ref).create(input); }
@Test public void invalidBaseRevision() throws Exception { grantTagPermissions(); TagInput input = new TagInput(); input.ref = "test"; input.revision = "abcdefg"; exception.expect(BadRequestException.class); exception.expectMessage("Invalid base revision"); tag(input.ref).create(input); }
@Test public void listTagsOfNonVisibleBranch() throws Exception { grantTagPermissions(); PushOneCommit push1 = pushFactory.create(db, admin.getIdent(), testRepo); PushOneCommit.Result r1 = push1.to("refs/heads/master"); r1.assertOkStatus(); TagInput tag1 = new TagInput(); tag1.ref = "v1.0"; tag1.revision = r1.getCommit().getName(); TagInfo result = tag(tag1.ref).create(tag1).get(); assertThat(result.ref).isEqualTo(R_TAGS + tag1.ref); assertThat(result.revision).isEqualTo(tag1.revision); pushTo("refs/heads/hidden"); PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), testRepo); PushOneCommit.Result r2 = push2.to("refs/heads/hidden"); r2.assertOkStatus(); TagInput tag2 = new TagInput(); tag2.ref = "v2.0"; tag2.revision = r2.getCommit().getName(); result = tag(tag2.ref).create(tag2).get(); assertThat(result.ref).isEqualTo(R_TAGS + tag2.ref); assertThat(result.revision).isEqualTo(tag2.revision); List<TagInfo> tags = getTags().get(); assertThat(tags).hasSize(2); assertThat(tags.get(0).ref).isEqualTo(R_TAGS + tag1.ref); assertThat(tags.get(0).revision).isEqualTo(tag1.revision); assertThat(tags.get(1).ref).isEqualTo(R_TAGS + tag2.ref); assertThat(tags.get(1).revision).isEqualTo(tag2.revision); blockRead("refs/heads/hidden"); tags = getTags().get(); assertThat(tags).hasSize(1); assertThat(tags.get(0).ref).isEqualTo(R_TAGS + tag1.ref); assertThat(tags.get(0).revision).isEqualTo(tag1.revision); }
@Test public void lightweightTag() throws Exception { grantTagPermissions(); PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo); PushOneCommit.Result r = push.to("refs/heads/master"); r.assertOkStatus(); TagInput input = new TagInput(); input.ref = "v1.0"; input.revision = r.getCommit().getName(); TagInfo result = tag(input.ref).create(input).get(); assertThat(result.ref).isEqualTo(R_TAGS + input.ref); assertThat(result.revision).isEqualTo(input.revision); input.ref = "refs/tags/v2.0"; result = tag(input.ref).create(input).get(); assertThat(result.ref).isEqualTo(input.ref); assertThat(result.revision).isEqualTo(input.revision); eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision); }
@Test public void annotatedTag() throws Exception { grantTagPermissions(); PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo); PushOneCommit.Result r = push.to("refs/heads/master"); r.assertOkStatus(); TagInput input = new TagInput(); input.ref = "v1.0"; input.revision = r.getCommit().getName(); input.message = "annotation message"; TagInfo result = tag(input.ref).create(input).get(); assertThat(result.ref).isEqualTo(R_TAGS + input.ref); assertThat(result.object).isEqualTo(input.revision); assertThat(result.message).isEqualTo(input.message); assertThat(result.tagger.name).isEqualTo(admin.fullName); assertThat(result.tagger.email).isEqualTo(admin.email); eventRecorder.assertRefUpdatedEvents(project.get(), result.ref, null, result.revision); // A second tag pushed on the same ref should have the same ref TagInput input2 = new TagInput(); input2.ref = "refs/tags/v2.0"; input2.revision = input.revision; input2.message = "second annotation message"; TagInfo result2 = tag(input2.ref).create(input2).get(); assertThat(result2.ref).isEqualTo(input2.ref); assertThat(result2.object).isEqualTo(input2.revision); assertThat(result2.message).isEqualTo(input2.message); assertThat(result2.tagger.name).isEqualTo(admin.fullName); assertThat(result2.tagger.email).isEqualTo(admin.email); eventRecorder.assertRefUpdatedEvents(project.get(), result2.ref, null, result2.revision); }