瀏覽代碼

feat(api): new RRsets need to have records (no more "new no-op RRsets")

Peter Thomassen 6 年之前
父節點
當前提交
6ce0b550f4
共有 2 個文件被更改,包括 8 次插入51 次删除
  1. 8 11
      api/desecapi/serializers.py
  2. 0 40
      test/e2e/spec/api_spec.js

+ 8 - 11
api/desecapi/serializers.py

@@ -125,18 +125,15 @@ class RRsetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
                 rrset.type = data.get('type', rrset.type)
                 rrset.ttl = data.get('ttl', rrset.ttl)
             else:
-                # No known instance (creation or meaningless request)
+                # No known instance (creation)
+                rrset_errors = {}
                 if 'ttl' not in data:
-                    if records:
-                        # If we have records, this is a creation request, so we
-                        # need a TTL.
-                        errors.append({'ttl': ['This field is required for new RRsets.']})
-                        continue
-                    else:
-                        # If this request is meaningless, we still want it to
-                        # be processed by pdns for type validation. In this
-                        # case, we need some dummy TTL.
-                        data['ttl'] = data.get('ttl', 1)
+                    rrset_errors['ttl'] = ['This field is required for new RRsets.']
+                if records is None:
+                    rrset_errors['records'] = ['This field is required for new RRsets.']
+                if rrset_errors:
+                    errors.append(rrset_errors)
+                    continue
                 data.pop('id', None)
                 data['domain'] = domain
                 rrset = RRset(**data)

+ 0 - 40
test/e2e/spec/api_spec.js

@@ -1025,46 +1025,6 @@ describe("API v1", function () {
                             return expect(response).to.have.status(404);
                         });
                     });
-
-                    describe("accepts missing fields for no-op requests via bulk-patch", function () {
-                        var response;
-
-                        before(function () {
-                            response = chakram.patch(
-                                '/domains/' + domain + '/rrsets/',
-                                [
-                                    {'subname': 'a.2', 'type': 'A', 'records': ['6.6.6.6']}, // existing RRset; TTL not needed
-                                    {'subname': 'b.2', 'type': 'A', 'ttl': 40}, // existing RRset; records not needed
-                                    {'subname': 'x.2', 'type': 'A', 'records': []}, // non-existent, no-op
-                                    {'subname': 'x.2', 'type': 'AAAA'}, // non-existent, no-op
-                                    {'subname': 'x.2', 'type': 'TXT', 'ttl': 32}, // non-existent, no-op
-                                ]
-                            );
-                            return expect(response).to.have.status(200);
-                        });
-
-                        it("gives the right response", function () {
-                            var response = chakram.get('/domains/' + domain + '/rrsets/b.2.../A/');
-                            expect(response).to.have.status(200);
-                            expect(response).to.have.json('ttl', 40);
-                            return chakram.wait();
-                        });
-                    });
-
-                    describe("catches invalid type for no-op request via bulk-patch", function () {
-                        it("gives the right response", function () {
-                            return chakram.patch(
-                                '/domains/' + domain + '/rrsets/',
-                                [
-                                    {'subname': 'x.2', 'type': 'AAA'}, // non-existent, no-op, but invalid type
-                                ]
-                            ).then(function (respObj) {
-                                expect(respObj).to.have.status(422);
-                                expect(respObj.body.detail).to.match(/IN AAA: unknown type given$/);
-                                return chakram.wait();
-                            });
-                        });
-                    });
                 });
 
                 describe("cannot bulk-patch with invalid input", function () {